Expr.cpp revision 9ec55f24b8f848bb37a9971100cf2fca379d5572
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" 2608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 27da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 282fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Lex/Lexer.h" 292fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Lex/LiteralSupport.h" 302fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/Sema/SemaDiagnostic.h" 31cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 33ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 3464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman#include <cstring> 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 378d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindolaconst CXXRecordDecl *Expr::getBestDynamicClassType() const { 38632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola const Expr *E = ignoreParenBaseCasts(); 390b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 400b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola QualType DerivedType = E->getType(); 410b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola if (const PointerType *PTy = DerivedType->getAs<PointerType>()) 420b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola DerivedType = PTy->getPointeeType(); 430b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 44251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola if (DerivedType->isDependentType()) 45251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola return NULL; 46251c449b280eb845017a6c022ed7189d17c63d49Rafael Espindola 470b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola const RecordType *Ty = DerivedType->castAs<RecordType>(); 480b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola Decl *D = Ty->getDecl(); 490b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola return cast<CXXRecordDecl>(D); 500b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola} 510b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 520a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindolaconst Expr * 530a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael EspindolaExpr::skipRValueSubobjectAdjustments( 540a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { 550a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr *E = this; 560a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola while (true) { 570a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = E->IgnoreParens(); 580a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 590a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { 600a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if ((CE->getCastKind() == CK_DerivedToBase || 610a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola CE->getCastKind() == CK_UncheckedDerivedToBase) && 620a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E->getType()->isRecordType()) { 630a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = CE->getSubExpr(); 640a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola CXXRecordDecl *Derived 650a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl()); 660a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(CE, Derived)); 670a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 680a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 690a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 700a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (CE->getCastKind() == CK_NoOp) { 710a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = CE->getSubExpr(); 720a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 730a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 740a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { 750a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (!ME->isArrow() && ME->getBase()->isRValue()) { 760a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola assert(ME->getBase()->getType()->isRecordType()); 770a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) { 780a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = ME->getBase(); 790a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(Field)); 800a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola continue; 810a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 820a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 830a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 840a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (BO->isPtrMemOp()) { 85ef4b666e841e3917385892713612888ec6c3a056Rafael Espindola assert(BO->getRHS()->isRValue()); 860a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = BO->getLHS(); 870a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const MemberPointerType *MPT = 880a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola BO->getRHS()->getType()->getAs<MemberPointerType>(); 890a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); 900a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 910a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 920a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 930a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Nothing changed. 940a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola break; 950a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 960a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola return E; 970a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola} 980a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 990a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindolaconst Expr * 1000a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael EspindolaExpr::findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const { 1010a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr *E = this; 1020a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Look through single-element init lists that claim to be lvalues. They're 1030a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // just syntactic wrappers in this case. 1040a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const InitListExpr *ILE = dyn_cast<InitListExpr>(E)) { 1050a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (ILE->getNumInits() == 1 && ILE->isGLValue()) 1060a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = ILE->getInit(0); 1070a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 1080a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1090a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola // Look through expressions for materialized temporaries (for now). 1100a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const MaterializeTemporaryExpr *M 1110a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola = dyn_cast<MaterializeTemporaryExpr>(E)) { 1120a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola MTE = M; 1130a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = M->GetTemporaryExpr(); 1140a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 1150a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1160a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola if (const CXXDefaultArgExpr *DAE = dyn_cast<CXXDefaultArgExpr>(E)) 1170a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola E = DAE->getExpr(); 1180a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola return E; 1190a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola} 1200a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 1212b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 1222b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 1232b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 1242b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 1252b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 126f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 127f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1282b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 129f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (E->getType()->isBooleanType()) return true; 130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 131f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!E->getType()->isIntegralOrEnumerationType()) return false; 132c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 133f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { 1342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 1352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 1362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 1372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 1382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 1392b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 1402b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1426907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 1436907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 144f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) 1452b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 146c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 147f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 1482b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 1492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 1502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 1512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 1522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 1532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 1542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 1552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 1562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 1572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 1582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 1612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 1622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 1632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 1642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 1652b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 166c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 1692b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 1702b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 1712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 172c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 173f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) 1742b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 1752b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 176c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 1782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 1792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 18063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 18163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 18290e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// 18390e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar// See also Stmt.cpp:{getLocStart(),getLocEnd()}. 18463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 18563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 18663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 18763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 18863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 18963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 19063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 19163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 19363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 19463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 19563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 19663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 19763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 19863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 19963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 20090e25a8b2cc5d006e4ced052bcdb40c8af999456Daniel Dunbar return static_cast<const E*>(expr)->getLocStart(); 20163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 20263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 20363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 20463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 20563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 20663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 20763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 20863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 20963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 21063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 21163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 21263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 21363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 21463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 21563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 21663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 221561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// \brief Compute the type-, value-, and instantiation-dependence of a 222561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// declaration reference 223d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 2243d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarstatic void computeDeclRefDependence(ASTContext &Ctx, NamedDecl *D, QualType T, 225d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 226561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ValueDependent, 227561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 228d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 229d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 230561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = false; 2310da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 2320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 2330da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 2340da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 235c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 2360da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 2370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 2380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 239d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 2410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 242d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 243d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 244d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 245561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 246d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (T->isInstantiationDependentType()) { 248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 2490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 250d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 252d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 253561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor == DeclarationName::CXXConversionFunctionName) { 254561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualType T = D->getDeclName().getCXXNameType(); 255561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isDependentType()) { 256561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeDependent = true; 257561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ValueDependent = true; 258561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 259561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return; 260561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 261561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 262561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isInstantiationDependentType()) 263561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 2640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 265561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 2660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 267d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 268d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 269561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 270d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 271d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 272d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 2740da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 275db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - a constant with literal type and is initialized with an 276db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11]. 277db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // (VD) - FIXME: Missing from the standard: 278db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // - an entity with reference type and is initialized with an 279db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith // expression that is value-dependent [C++11] 280d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 28180ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if ((Ctx.getLangOpts().CPlusPlus11 ? 282db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isLiteralType() : 283db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isIntegralOrEnumerationType()) && 2844ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie (Var->getType().isConstQualified() || 285db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getType()->isReferenceType())) { 28631310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 287561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Init->isValueDependent()) { 288d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 289561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 290561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 291db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 292db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith 293bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 294bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 295bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 296db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith if (Var->isStaticDataMember() && 297db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith Var->getDeclContext()->isDependentContext()) { 298d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 300561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 301d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 302d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 303d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 304d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 305bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 306bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 307bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 308d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 309d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 310561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 311db1822c6de43ff4aa5fa00234bf8222f6f4816e8Richard Smith } 312d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 313d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 3143d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbarvoid DeclRefExpr::computeDependence(ASTContext &Ctx) { 315d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 316d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 317561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 3183d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, 3193d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar ValueDependent, InstantiationDependent); 320d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 321d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 322d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 323d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 324d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 325d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 326d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 327d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 328d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 329d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 330d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 331d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 332561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getNumTemplateArgs(), 333561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) { 334d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 335d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 336561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 337d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 338d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 339d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 340d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 341561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 342d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 34310738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 344d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 3451fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 3470da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 3483d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel DunbarDeclRefExpr::DeclRefExpr(ASTContext &Ctx, 3493d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 350e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 351f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool RefersToEnclosingLocal, 352f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 3533aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 356561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 357cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 358cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; 3597e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth if (QualifierLoc) 3606857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth getInternalQualifierLoc() = QualifierLoc; 3613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; 3623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 3633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth getInternalFoundDecl() = FoundD; 364e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo 365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; 366f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = RefersToEnclosingLocal; 367561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TemplateArgs) { 368561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 369561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 370561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 375561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 376561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(true); 377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 379561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 380b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer DeclRefExprBits.HadMultipleCandidates = 0; 381b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer 3823d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(Ctx); 3832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 385a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 38640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 387e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 388dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 389f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 390a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 3910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 392f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return Create(Context, QualifierLoc, TemplateKWLoc, D, 396f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 3972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 3983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK, FoundD, TemplateArgs); 3992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 4002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4012577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 40240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 403e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 4042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 405f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool RefersToEnclosingLocal, 4062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 4072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 408f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 4093aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 4102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 4113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth // Filter out cases where the found Decl is the same as the value refenenced. 4123aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (D == FoundD) 4133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth FoundD = 0; 4143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 415a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 41640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc != 0) 4176857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 4183aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 4193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 420d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 421e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); 422e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 423e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 4243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 4253248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 4263d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, 427f4b88a45902af1802a1cb42ba48b1c474474f228John McCall RefersToEnclosingLocal, 4283d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NameInfo, FoundD, TemplateArgs, T, VK); 429a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4313aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 432def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 4333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 434e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 435663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 436663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 437663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 4386857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 4393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (HasFoundDecl) 4403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 441e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (HasTemplateKWAndArgsInfo) 442e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 4433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 4443248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 445663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 446663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 447663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 448396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocStart() const { 449396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasQualifier()) 450396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 451396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocStart(); 452396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 453396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation DeclRefExpr::getLocEnd() const { 454396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 455396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getRAngleLoc(); 456396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getNameInfo().getLocEnd(); 457396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 458a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4593a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 4603a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 461848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 462848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 463848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 4643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 465848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 4663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 4673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 468f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 4693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 4703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 472848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 4733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 4744eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 4754eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 4763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4784e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie PrintingPolicy Policy(Context.getLangOpts()); 4793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 480abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream POut(Proto); 4813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 482abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionDecl *Decl = FD; 483abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) 484abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Decl = Pattern; 485abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); 4863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 4873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 4883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 4893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 490abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << "("; 4913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 492abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { 4933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 4947ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis POut << Decl->getParamDecl(i)->getType().stream(Policy); 4953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 4983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 4993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 5003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 502abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << ")"; 5033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5044eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 5054ae711b5ef292378d5b88cede3d4b708174053e2Argyrios Kyrtzidis const FunctionType *FT = MD->getType()->castAs<FunctionType>(); 5064ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isConst()) 507abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " const"; 5084ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie if (FT->isVolatile()) 509abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " volatile"; 510abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor RefQualifierKind Ref = MD->getRefQualifier(); 511abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Ref == RQ_LValue) 512abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &"; 513abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor else if (Ref == RQ_RValue) 514abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " &&"; 515abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 516abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 517abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; 518abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor SpecsTy Specs; 519abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const DeclContext *Ctx = FD->getDeclContext(); 520abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor while (Ctx && isa<NamedDecl>(Ctx)) { 521abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const ClassTemplateSpecializationDecl *Spec 522abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); 523abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Spec && !Spec->isExplicitSpecialization()) 524abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Specs.push_back(Spec); 525abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Ctx = Ctx->getParent(); 526abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 527abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 528abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor std::string TemplateParams; 529abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor llvm::raw_string_ostream TOut(TemplateParams); 530abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); 531abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor I != E; ++I) { 532abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList *Params 533abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = (*I)->getSpecializedTemplate()->getTemplateParameters(); 534abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList &Args = (*I)->getTemplateArgs(); 535abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args.size()); 536abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) { 537abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 538abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 539abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 540abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args.get(i).print(Policy, TOut); 541abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 542abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 5434eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 5444eadcc569223135e13353c9381b448986e3f7053Sam Weinig 545abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor FunctionTemplateSpecializationInfo *FSI 546abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FD->getTemplateSpecializationInfo(); 547abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (FSI && !FSI->isExplicitSpecialization()) { 548abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateParameterList* Params 549abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor = FSI->getTemplate()->getTemplateParameters(); 550abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor const TemplateArgumentList* Args = FSI->TemplateArguments; 551abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor assert(Params->size() == Args->size()); 552abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor for (unsigned i = 0, e = Params->size(); i != e; ++i) { 553abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor StringRef Param = Params->getParam(i)->getName(); 554abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (Param.empty()) continue; 555abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << Param << " = "; 556abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor Args->get(i).print(Policy, TOut); 557abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut << ", "; 558abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 559abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 560abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 561abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TOut.flush(); 562abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor if (!TemplateParams.empty()) { 563abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor // remove the trailing comma and space 564abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor TemplateParams.resize(TemplateParams.size() - 2); 565abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut << " [" << TemplateParams << "]"; 566abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor } 567abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 568abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor POut.flush(); 569abf65ce5ddfb8db0d34280d30a91253930732f4fDouglas Gregor 5703a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 5713a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 5723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 5743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 5783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 579f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> Name; 5803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 5813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 5823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 583b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 584b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 585b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 586b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 587b8989f27f116ff2400e92a52c067a69846119eb5Benjamin Kramer Out << *ID; 588b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 5893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 590900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 591f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramer Out << '(' << *CID << ')'; 592900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 5933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 5943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 5953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 5963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 5973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 5983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 5993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 6003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 6013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 6023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 6033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 6043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 6053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 6063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 6079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 6089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 6099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 6109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 6129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 6139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 6149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 6159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 6169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 6179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 6189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 6199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 6209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 6219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 623478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerIntegerLiteral::IntegerLiteral(ASTContext &C, const llvm::APInt &V, 624478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer QualType type, SourceLocation l) 625478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 626478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), 627478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer Loc(l) { 628478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 629478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer assert(V.getBitWidth() == C.getIntWidth(type) && 630478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer "Integer type is not the correct size for constant."); 631478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 632478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 633478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 6349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 6359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 6369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 6379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 6389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 6419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 6429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 6439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 645478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, const llvm::APFloat &V, 646478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer bool isexact, QualType Type, SourceLocation L) 647478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 648478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer false, false), Loc(L) { 6499ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover setSemantics(V.getSemantics()); 650478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = isexact; 651478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer setValue(C, V); 652478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 653478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 654478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin KramerFloatingLiteral::FloatingLiteral(ASTContext &C, EmptyShell Empty) 655478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer : Expr(FloatingLiteralClass, Empty) { 6569ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover setRawSemantics(IEEEhalf); 657478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer FloatingLiteralBits.IsExact = false; 658478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer} 659478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer 6609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 6629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 6639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 6649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 6679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 66831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return new (C) FloatingLiteral(C, Empty); 6699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 6709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 6719ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northoverconst llvm::fltSemantics &FloatingLiteral::getSemantics() const { 6729ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover switch(FloatingLiteralBits.Semantics) { 6739ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEhalf: 6749ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEhalf; 6759ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEsingle: 6769ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEsingle; 6779ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEdouble: 6789ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEdouble; 6799ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case x87DoubleExtended: 6809ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::x87DoubleExtended; 6819ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case IEEEquad: 6829ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::IEEEquad; 6839ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover case PPCDoubleDouble: 6849ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat::PPCDoubleDouble; 6859ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover } 6869ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover llvm_unreachable("Unrecognised floating semantics"); 6879ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover} 6889ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 6899ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northovervoid FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { 6909ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover if (&Sem == &llvm::APFloat::IEEEhalf) 6919ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEhalf; 6929ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEsingle) 6939ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEsingle; 6949ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEdouble) 6959ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEdouble; 6969ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::x87DoubleExtended) 6979ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = x87DoubleExtended; 6989ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::IEEEquad) 6999ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = IEEEquad; 7009ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else if (&Sem == &llvm::APFloat::PPCDoubleDouble) 7019ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = PPCDoubleDouble; 7029ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover else 7039ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover llvm_unreachable("Unknown floating semantics"); 7049ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover} 7059ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 706da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 707da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 708da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 709da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 710da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 711ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 712ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 713ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 714da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 715da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 716da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 7170fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewyckyint StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { 718fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman int CharByteWidth = 0; 7190fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky switch(k) { 72064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Ascii: 72164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF8: 7220fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getCharWidth(); 72364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 72464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case Wide: 7250fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getWCharWidth(); 72664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 72764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF16: 7280fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar16Width(); 72964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 73064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case UTF32: 7310fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = target.getChar32Width(); 732fd819783aafa39b3bfdfcc095270352074ef4734Eli Friedman break; 73364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 73464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); 73564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman CharByteWidth /= 8; 7360fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 73764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "character byte widths supported are 1, 2, and 4 only"); 73864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return CharByteWidth; 73964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman} 74064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 7415f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, 7425cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind Kind, bool Pascal, QualType Ty, 7431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 744a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 7452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 7462085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 7472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 7482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 7493248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 7502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 75364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->setString(C,Str,Kind,Pascal); 75464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 7552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 7562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 758726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 7592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 7602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 761726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 762726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 763673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 764673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 765673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 7663248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 767673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 76864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->CharByteWidth = 0; 76964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman SL->Length = 0; 770673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 771673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 772673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 773673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 7748ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieuvoid StringLiteral::outputString(raw_ostream &OS) { 7758ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (getKind()) { 7768ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Ascii: break; // no prefix. 7778ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case Wide: OS << 'L'; break; 7788ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF8: OS << "u8"; break; 7798ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF16: OS << 'u'; break; 7808ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case UTF32: OS << 'U'; break; 7818ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 7828ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 7838ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu static const char Hex[] = "0123456789ABCDEF"; 7848ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7858ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu unsigned LastSlashX = getLength(); 7868ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (unsigned I = 0, N = getLength(); I != N; ++I) { 7878ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (uint32_t Char = getCodeUnit(I)) { 7888ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu default: 7898ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Convert UTF-8 back to codepoints before rendering. 7908ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 7918ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Convert UTF-16 surrogate pairs back to codepoints before rendering. 7928ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Leave invalid surrogates alone; we'll use \x for those. 7938ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == UTF16 && I != N - 1 && Char >= 0xd800 && 7948ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char <= 0xdbff) { 7958ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu uint32_t Trail = getCodeUnit(I + 1); 7968ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Trail >= 0xdc00 && Trail <= 0xdfff) { 7978ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); 7988ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu ++I; 7998ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8008ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8018ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8028ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xff) { 8038ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If this is a wide string, output characters over 0xff using \x 8048ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a 8058ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // codepoint: use \x escapes for invalid codepoints. 8068ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (getKind() == Wide || 8078ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) { 8088ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // FIXME: Is this the best way to print wchar_t? 8098ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\x"; 8108ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu int Shift = 28; 8118ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu while ((Char >> Shift) == 0) 8128ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu Shift -= 4; 8138ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu for (/**/; Shift >= 0; Shift -= 4) 8148ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> Shift) & 15]; 8158ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu LastSlashX = I; 8168ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8178ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8188ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8198ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (Char > 0xffff) 8208ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\U00" 8218ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 20) & 15] 8228ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 16) & 15]; 8238ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else 8248ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\\u"; 8258ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << Hex[(Char >> 12) & 15] 8268ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 8) & 15] 8278ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 4) & 15] 8288ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << Hex[(Char >> 0) & 15]; 8298ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8308ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8318ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8328ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // If we used \x... for the previous character, and this character is a 8338ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // hexadecimal digit, prevent it being slurped as part of the \x. 8348ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (LastSlashX + 1 == I) { 8358ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu switch (Char) { 8368ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '0': case '1': case '2': case '3': case '4': 8378ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '5': case '6': case '7': case '8': case '9': 8388ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 8398ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 8408ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << "\"\""; 8418ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8428ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8438ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8448ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu assert(Char <= 0xff && 8458ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu "Characters above 0xff should already have been handled."); 8468ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 8478ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu if (isprint(Char)) 8488ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << (char)Char; 8498ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu else // Output anything hard as an octal escape. 8508ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '\\' 8518ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 6) & 7)) 8528ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 3) & 7)) 8538ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu << (char)('0' + ((Char >> 0) & 7)); 8548ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu break; 8558ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu // Handle some common non-printable cases to make dumps prettier. 8568ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\\': OS << "\\\\"; break; 8578ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '"': OS << "\\\""; break; 8588ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\n': OS << "\\n"; break; 8598ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\t': OS << "\\t"; break; 8608ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\a': OS << "\\a"; break; 8618ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu case '\b': OS << "\\b"; break; 8628ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8638ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu } 8648ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu OS << '"'; 8658ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu} 8668ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 86764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedmanvoid StringLiteral::setString(ASTContext &C, StringRef Str, 86864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal) { 86964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman //FIXME: we assume that the string data comes from a target that uses the same 87064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman // code unit size and endianess for the type of string. 87164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->Kind = Kind; 87264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman this->IsPascal = IsPascal; 87364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 8740fd7f4db69ea75bde3d5fd7365165c6f43d78be5Nick Lewycky CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); 87564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((Str.size()%CharByteWidth == 0) 87664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "size of data must be multiple of CharByteWidth"); 87764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman Length = Str.size()/CharByteWidth; 87864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 87964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman switch(CharByteWidth) { 88064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 1: { 88164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman char *AStrData = new (C) char[Length]; 88266dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 88364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asChar = AStrData; 88464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 88564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 88664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 2: { 88764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint16_t *AStrData = new (C) uint16_t[Length]; 88866dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 88964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt16 = AStrData; 89064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 89164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 89264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman case 4: { 89364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t *AStrData = new (C) uint32_t[Length]; 89466dfef17b8da7c89e20f32d4f0f4a04691b79768Argyrios Kyrtzidis std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); 89564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StrData.asUInt32 = AStrData; 89664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman break; 89764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 89864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman default: 89964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(false && "unsupported CharByteWidth"); 90064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 901673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 902673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 90308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 90408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 90508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 90608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 90708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 90808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 90908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 91008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 91108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 91208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 913df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith assert((Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) && 914df9ef1bc8c3780307ab2ed81bf5e31c23310b936Richard Smith "Only narrow string literals are currently supported"); 9155cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 91608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 91708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 91808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 91908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 92008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 92108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 92208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 92308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 92408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 92508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 92608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 92708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 92808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 92908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 93008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 9315f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 93208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 93308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 93408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 93508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 93608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 93708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 938df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, 939df8755884e039d3f313ee0fea42b955257b5e240Argyrios Kyrtzidis Buffer.begin(), StrData, Buffer.end()); 94008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 94108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 94208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 94308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 94408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 94508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 94608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 94708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 94808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 949935a70c1e76d78985f20d422940280161b941299Hans Wennborg (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { 95008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 95108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 95208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 95308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 95408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 95508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 95608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 95708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 95808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 95908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 96008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 96108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 96208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 96308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 96408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 9670bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef UnaryOperator::getOpcodeStr(Opcode Op) { 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 9692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 9702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 9712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 9722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 9732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 9742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 9752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 9762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 9772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 9782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 9792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 9802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 9812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 983561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("Unknown unary operator"); 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 987bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 988bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 989b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("No unary operator for overloaded function"); 9902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 9912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 9922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 9932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 9942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 9952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 9962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 9972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 998bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 999bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 1000bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1001bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 1002bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 10032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 10042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 10052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 10062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 10072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 10082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 10092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 10102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 1011bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 1012bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 1013bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 1014bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1015bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1020cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 10213b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 1022f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 1023f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 1024bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 1025bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 1026561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 1027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 10283b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 10291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10303b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START+NumPreArgs]; 1031b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 10323b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 1033bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 1034bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 1035bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 1036bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 1037561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 1038561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1039bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 1040bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1041bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1042cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 1043bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 1044668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 1045cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 1046b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 1047b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 1048e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 10493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerCallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, 1050f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 1051f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 1052bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 1053bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 1054561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 1055bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 10563b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumArgs(args.size()) { 1057668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 10583b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()+PREARGS_START]; 105977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 10603b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); ++i) { 1061bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 1062bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 1063bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 1064bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 1065561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 1066561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1067bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 1068bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1069bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1070cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 1071bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 1072668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 1073cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 1079bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 1080cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 1081cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 1082cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 1083cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1084cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 1085cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 1086cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 1087cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 1088cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 1089cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 10901f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 10911f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1092d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 1093e8683d6d389def2fce229325435ba3c2b3f75492John McCall Expr *CEE = getCallee()->IgnoreParenImpCasts(); 10941ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 10951ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor while (SubstNonTypeTemplateParmExpr *NTTP 10961ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { 10971ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor CEE = NTTP->getReplacement()->IgnoreParenCasts(); 10981ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor } 10991ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 1100200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 1101200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 1102200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 1103200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 1104200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 1105200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 1106200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 1107200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 11086346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 1109d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 1110cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 1111cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 1112a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1113a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 1114a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 1115a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1116d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 1117caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 1118d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 1119d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1120d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 1121d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 1122d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 11238189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 1124d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 1125d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1127d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 1128d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 1129d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1130d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 1131d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 1132d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1133d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 1134cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 1135cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 1136d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 1137cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 1138d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 1139d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 1140cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 1141cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 1142d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114488c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 1145d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 1146d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 1147d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 1148d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 1149cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1150cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 1151180f47959a066795cc0f409433023af448bb0328Richard Smithunsigned CallExpr::isBuiltinCall() const { 1152c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 1154c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 1155c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 1156c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 1157cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1159c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 1160c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 1161cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 1164bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 1165cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11674fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 11684fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 11694fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 11707814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 1171cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 1172bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 1173ba57183965f117279342903edec19766e478c9a8Richard Smithbool CallExpr::isUnevaluatedBuiltinCall(ASTContext &Ctx) const { 1174ba57183965f117279342903edec19766e478c9a8Richard Smith if (unsigned BI = isBuiltinCall()) 1175ba57183965f117279342903edec19766e478c9a8Richard Smith return Ctx.BuiltinInfo.isUnevaluated(BI); 1176ba57183965f117279342903edec19766e478c9a8Richard Smith return false; 1177ba57183965f117279342903edec19766e478c9a8Richard Smith} 1178ba57183965f117279342903edec19766e478c9a8Richard Smith 11796dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 11806dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 11816217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 11826dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 11836217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 11846dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 1185864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) 1186864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // This should never be overloaded and so should never return null. 1187864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall CalleeType = Expr::findBoundMemberType(getCallee()); 11885291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 1189864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall const FunctionType *FnType = CalleeType->castAs<FunctionType>(); 11906dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 11916dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 1192cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 11938fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocStart() const { 11948fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 119565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return cast<CXXOperatorCallExpr>(this)->getLocStart(); 11968fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 11978fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation begin = getCallee()->getLocStart(); 11988fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (begin.isInvalid() && getNumArgs() > 0) 11998fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar begin = getArg(0)->getLocStart(); 12008fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return begin; 12018fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 12028fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel DunbarSourceLocation CallExpr::getLocEnd() const { 12038fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (isa<CXXOperatorCallExpr>(this)) 120465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return cast<CXXOperatorCallExpr>(this)->getLocEnd(); 12058fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar 12068fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar SourceLocation end = getRParenLoc(); 12078fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar if (end.isInvalid() && getNumArgs() > 0) 12088fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar end = getArg(getNumArgs() - 1)->getLocEnd(); 12098fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar return end; 12108fbc6d23d61213750ba1fdcb0b4b9d3d54bbc32fDaniel Dunbar} 12112882eca5a184c78f793188083f6ce539740a5cf2John McCall 1212c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 12138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 1214c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 12153b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, 12163b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 12178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 12188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 12193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(OffsetOfNode) * comps.size() + 12203b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Expr*) * exprs.size()); 12218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12223b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, 12233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer RParenLoc); 12248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 12278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 12288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 12298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 12308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 12318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 12328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1234c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 12358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 12363b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, 12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 1238f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 1239f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 1240bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 1241561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tsi->getType()->isInstantiationDependentType(), 1242bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 1243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 12443b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumComps(comps.size()), NumExprs(exprs.size()) 12458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 12463b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != comps.size(); ++i) { 12473b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setComponent(i, comps[i]); 12488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1249c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 12513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent()) 1252bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 12533b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer if (exprs[i]->containsUnexpandedParameterPack()) 1254bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 1255bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 12563b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer setIndexExpr(i, exprs[i]); 12578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 12618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 12628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 12638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 1264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 12668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 126940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1270e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1271f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 1272161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 12732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 1274d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 1276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 1277f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 127883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 12796bb8017bb9e828d118e15e59d71c66bba323c364John McCall 128040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor bool hasQualOrFound = (QualifierLoc || 1281161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 1282161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 12836bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 12846bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1286d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 1287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(targs->size()); 1288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara else if (TemplateKWLoc.isValid()) 1289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Size += ASTTemplateKWAndArgsInfo::sizeFor(0); 12901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12913248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 1292f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 1293f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 12946bb8017bb9e828d118e15e59d71c66bba323c364John McCall 12956bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 129640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor // FIXME: Wrong. We should be looking at the member declaration we found. 129740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { 12986bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 12996bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 1300561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1301561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1302561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (QualifierLoc && 1303561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) 1304561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1305561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 13066bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 13076bb8017bb9e828d118e15e59d71c66bba323c364John McCall 13086bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 130940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NQ->QualifierLoc = QualifierLoc; 13106bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 13116bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 13126bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1313e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid()); 1314e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 13156bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 1316561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 1317561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 1318561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 1319e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *targs, 1320e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara Dependent, 1321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara InstantiationDependent, 1322e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ContainsUnexpandedParameterPack); 1323561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 1324561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 1325e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } else if (TemplateKWLoc.isValid()) { 1326e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara E->getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 13276bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 13286bb8017bb9e828d118e15e59d71c66bba323c364John McCall 13296bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 133083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 133183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1332396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocStart() const { 133375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (isImplicitAccess()) { 133475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (hasQualifier()) 1335396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getQualifierLoc().getBeginLoc(); 1336396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 133775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 1338e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1339396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // FIXME: We don't want this to happen. Rather, we should be able to 1340396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar // detect all kinds of implicit accesses more cleanly. 1341396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar SourceLocation BaseStartLoc = getBase()->getLocStart(); 1342396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (BaseStartLoc.isValid()) 1343396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return BaseStartLoc; 1344396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return MemberLoc; 1345396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar} 1346396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel DunbarSourceLocation MemberExpr::getLocEnd() const { 134713fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); 1348396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar if (hasExplicitTemplateArgs()) 134913fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara EndLoc = getRAngleLoc(); 135013fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara else if (EndLoc.isInvalid()) 135113fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara EndLoc = getBase()->getLocEnd(); 135213fd684ee2c7578177b7c741e8eeec91ae628fcfAbramo Bagnara return EndLoc; 135375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 135475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 13551d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCallvoid CastExpr::CheckCastConsistency() const { 13561d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall switch (getCastKind()) { 13571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBase: 13581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UncheckedDerivedToBase: 13591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBaseMemberPointer: 13601d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerived: 13611d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerivedMemberPointer: 13621d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 13631d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 13641d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 13661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 13671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isPointerType()); 13681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13701d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 13711d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 13721d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isBlockPointerType()); 13731d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13741d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13754d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 13764d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getType()->isMemberPointerType()); 13774d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall assert(getSubExpr()->getType()->isMemberPointerType()); 13784d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall goto CheckNoBasePath; 13794d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 13801d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BitCast: 13811d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Arbitrary casts to C pointer types count as bitcasts. 13821d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Otherwise, we should only have block and ObjC pointer casts 13831d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // here if they stay within the type kind. 13841d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (!getType()->isPointerType()) { 13851d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType() == 13861d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isObjCObjectPointerType()); 13871d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType() == 13881d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isBlockPointerType()); 13891d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 13901d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13911d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 13921d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_AnyPointerToBlockPointerCast: 13931d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType()); 13941d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isAnyPointerType() && 13951d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall !getSubExpr()->getType()->isBlockPointerType()); 13961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 13971d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1398ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1399ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getType()->isBlockPointerType()); 1400ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor assert(getSubExpr()->getType()->isBlockPointerType()); 1401ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor goto CheckNoBasePath; 1402a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 1403a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_FunctionToPointerDecay: 1404a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getType()->isPointerType()); 1405a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman assert(getSubExpr()->getType()->isFunctionType()); 1406a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman goto CheckNoBasePath; 1407a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 14081d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // These should not have an inheritance path. 14091d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dynamic: 14101d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToUnion: 14111d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ArrayToPointerDecay: 14121d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToMemberPointer: 14131d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToPointer: 14141d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ConstructorConversion: 14151d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToPointer: 14161d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToIntegral: 14171d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToVoid: 14181d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_VectorSplat: 14191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralCast: 14201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToFloating: 14211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToIntegral: 14221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingCast: 14231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ObjCObjectLValueCast: 14241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingRealToComplex: 14251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToReal: 14261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexCast: 14271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToIntegralComplex: 14281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralRealToComplex: 14291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToReal: 14301d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexCast: 14311d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToFloatingComplex: 143233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 143333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 143433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 143533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 1436e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case CK_ZeroToOCLEvent: 14371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 14381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 14391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 14401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dependent: 14411d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueToRValue: 14421d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NoOp: 14437a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 14447a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 14451d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToBoolean: 14461d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToBoolean: 14471d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToBoolean: 14481d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_MemberPointerToBoolean: 14491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToBoolean: 14501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToBoolean: 14511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueBitCast: // -> bool& 14521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UserDefinedConversion: // operator bool() 1453a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 14541d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CheckNoBasePath: 14551d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 14561d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 14571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 14581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall} 14591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1460f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 1461f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 1462daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 1463daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 14642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 1465f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 14662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 1467e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 14680ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 14690ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 14702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 1471f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 14722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 147311de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 14742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 1475f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 14762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 147723cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 14782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 1479f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 14802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 1481f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 14822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 1483f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 14842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 1485f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 14862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 1487f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 1488404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 1489404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 14902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 1491f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 14922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 14931a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 14944d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall case CK_ReinterpretMemberPointer: 14954d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall return "ReinterpretMemberPointer"; 14962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 1497f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 14982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 1499f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 15002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 15017f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 15022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 15037f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 1504daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 1505daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 15062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 1507ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 15082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 150916a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 15102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 151182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 1512daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 1513daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 15142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 151582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 15162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 151782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 15182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1519c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1520daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1521daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 15222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1523bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 15241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 15251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "CPointerToObjCPointerCast"; 15261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 15271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "BlockPointerToObjCPointerCast"; 15282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 15293b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 15302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1531569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 15322bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 15332bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1534f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1535f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1536f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1537f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 15382bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 15392bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1540f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1541f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 15422bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 15432bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1544f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1545f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1546f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1547f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 15482bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 15492bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1550f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1551f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 155233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 155333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCConsumeObject"; 155433e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 155533e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCProduceObject"; 155633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 155733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCReclaimReturnedObject"; 155833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 155933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCCExtendBlockObject"; 15607a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_AtomicToNonAtomic: 15617a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "AtomicToNonAtomic"; 15627a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall case CK_NonAtomicToAtomic: 15637a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return "NonAtomicToAtomic"; 1564ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor case CK_CopyAndAutoreleaseBlockObject: 1565ac1303eca6cbe3e623fb5ec6fe7ec184ef4b0dfaDouglas Gregor return "CopyAndAutoreleaseBlockObject"; 1566a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case CK_BuiltinFnToFnPtr: 1567a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman return "BuiltinFnToFnPtr"; 1568e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case CK_ZeroToOCLEvent: 1569e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei return "ZeroToOCLEvent"; 1570f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15722bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1573f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1574f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 15756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 15766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 15776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 15786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 15796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 158003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 158103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Skip through reference binding to temporary. 158203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 158303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) 158403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SubExpr = Materialize->GetTemporaryExpr(); 158503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 15866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 15876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 15886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1589c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 15916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 15922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 15936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 15942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 15956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 15986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1599c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1600c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 16026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 16036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1604f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1605f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1606f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1607f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1608f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1609f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1610f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1611f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1612f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1613f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1614f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1615f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1616f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1617f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1618f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1619f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1620f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1621f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1622f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1623f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1624f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 16255baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1626f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1627f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1628f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1629f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 16305baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1631f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1632f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1633f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1634f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1635f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1636f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1637f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1638f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1641f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1642f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1643f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1644f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1645f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1646f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1647f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1648f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1649f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1650f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1651f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1652f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1653f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1654f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1655f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1656f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1657f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1658f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1659f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1660f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1661f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1662f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 16650bea86307eb8c16339315a1e261fc490eb505c5bDavid BlaikieStringRef BinaryOperator::getOpcodeStr(Opcode Op) { 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 16672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 16682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 16692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 16702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 16712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 16722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 16732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 16742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 16752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 16762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 16772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 16782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 16792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 16802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 16812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 16822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 16832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 16842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 16852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 16862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 16872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 16882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 16892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 16902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 16912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 16922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 16932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 16942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 16952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 16962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 16972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 16982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1700baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 17013026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid OpCode!"); 17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1705063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1706063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1707b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not an overloadable binary operator"); 17082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 17092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 17102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 17112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 17122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 17132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 17142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 17152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 17162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 17172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 17182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 17192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 17202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 17212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 17222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 17232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 17242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 17252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 17262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 17272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 17282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 17292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 17302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 17312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 17322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 17332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 17342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 17352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 17362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 17372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 17382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1739063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1740063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1741063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1742063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1743063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1744063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1745063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1746063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1747063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1748063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1749063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1750063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1751063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1752063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1753063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1754063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1755063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1756063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1757063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1758063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1759063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1760063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1761063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1762063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1763063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1764063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1765063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1766709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 17673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) 1768bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1769561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 17703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs(C, initExprs.size()), 177123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(0, true) 177232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl{ 177332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl sawArrayRangeDesignator(false); 177432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl setInitializesStdInitializerList(false); 17753b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned I = 0; I != initExprs.size(); ++I) { 1776ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 17778e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1778ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 17798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1780561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (initExprs[I]->isInstantiationDependent()) 1781561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1782bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1783bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 178473460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1785c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 17863b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); 178766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1789709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1790ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1791709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1792fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1793fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1794709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1795709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 17964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 17974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1798709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1799ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1800709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1801ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1802ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 18034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 18041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 18064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 18074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 18084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 18094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 18103e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidisvoid InitListExpr::setArrayFiller(Expr *filler) { 181121f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis assert(!hasArrayFiller() && "Filler already set!"); 18123e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis ArrayFillerOrUnionFieldInit = filler; 18133e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis // Fill out any "holes" in the array due to designated initializers. 18143e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis Expr **inits = getInits(); 18153e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis for (unsigned i = 0, e = getNumInits(); i != e; ++i) 18163e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis if (inits[i] == 0) 18173e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis inits[i] = filler; 18183e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis} 18193e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis 1820fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smithbool InitListExpr::isStringLiteralInit() const { 1821fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith if (getNumInits() != 1) 1822fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1823f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); 1824f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman if (!AT || !AT->getElementType()->isIntegerType()) 1825fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return false; 1826f0a26499c0ef62c7940b596be092315922a46ab7Eli Friedman const Expr *Init = getInit(0)->IgnoreParens(); 1827fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); 1828fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith} 1829fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 183065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation InitListExpr::getLocStart() const { 183123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara if (InitListExpr *SyntacticForm = getSyntacticForm()) 183265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SyntacticForm->getLocStart(); 183365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation Beg = LBraceLoc; 1834c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1835c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1836c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1837c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1838c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1839c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1840c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1841c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1842c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1843c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1844c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 184565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Beg; 184665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen} 184765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 184865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation InitListExpr::getLocEnd() const { 184965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (InitListExpr *SyntacticForm = getSyntacticForm()) 185065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SyntacticForm->getLocEnd(); 185165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation End = RBraceLoc; 1852c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1853c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1854c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 185565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen E = InitExprs.rend(); 185665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen I != E; ++I) { 1857c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 185865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen End = S->getLocEnd(); 1859c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 186065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 1861c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1862c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 186365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return End; 1864c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1865c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1866bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 18674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 1868a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCallconst FunctionProtoType *BlockExpr::getFunctionType() const { 1869a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall // The block pointer is never sugared, but the function type might be. 1870a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall return cast<BlockPointerType>(getType()) 1871a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall ->getPointeeType()->castAs<FunctionProtoType>(); 18724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 18734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 18741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 187656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 18787297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 18797297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 18801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 18827297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 188356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 188456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 18855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 18875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1889026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1890026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1891026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1892026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1893a6115068cde719142eb394db88612c185cabd05bEli Friedmanbool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, 1894a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 1895a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const { 1896ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1897ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1898ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1899ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 19030faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 19040faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1905a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1906026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1907026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1908026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1910026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1911a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1912f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 1913f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()-> 1914a6115068cde719142eb394db88612c185cabd05bEli Friedman isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 19171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1919a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Plus: 1920a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Minus: 1921a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_AddrOf: 1922a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Not: 1923a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_LNot: 1924a6115068cde719142eb394db88612c185cabd05bEli Friedman case UO_Deref: 1925a6115068cde719142eb394db88612c185cabd05bEli Friedman break; 19262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 19272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 19282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 19292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1930026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 19312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 19322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1934df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1935df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1936026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1937026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 19382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1939a6115068cde719142eb394db88612c185cabd05bEli Friedman return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1941a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1942026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1943026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1944026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1946e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1947026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1948c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1949c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1950c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 195125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 195225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 19532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1954c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1955c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1956c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1957c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1958c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1959c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 1960a6115068cde719142eb394db88612c185cabd05bEli Friedman return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 196125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 19622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 19632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 1964a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || 1965a6115068cde719142eb394db88612c185cabd05bEli Friedman !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 196625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 196725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1968bf0ee354163f87623a4b60412544243911332343John McCall } 1969026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1970026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1971a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1972026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1973026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1974026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1975026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1976e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1977eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1978c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1979276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman case AtomicExprClass: 1980026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1982ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1983fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // If only one of the LHS or RHS is a warning, the operator might 1984fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // be being used for control flow. Only warn if both the LHS and 1985fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // RHS are warnings. 1986ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 1987a6115068cde719142eb394db88612c185cabd05bEli Friedman if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) 1988fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return false; 1989fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getLHS()) 1990026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1991a6115068cde719142eb394db88612c185cabd05bEli Friedman return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 1992ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1993ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 19945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1995a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 1996026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1997026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1998026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1999026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 2002a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2003026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 2004026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 2005026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 2006026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 2007211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 20089b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth case CXXOperatorCallExprClass: { 20099b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // We warn about operator== and operator!= even when user-defined operator 20109b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // overloads as there is no reasonable way to define these such that they 20119b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // have non-trivial, desirable side-effects. See the -Wunused-comparison 20129b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // warning: these operators are commonly typo'ed, and so warning on them 20139b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // provides additional value as well. If this list is updated, 20149b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // DiagnoseUnusedComparison should be as well. 20159b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); 20169b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth if (Op->getOperator() == OO_EqualEqual || 20176e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Op->getOperator() == OO_ExclaimEqual) { 2018a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20196e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Loc = Op->getOperatorLoc(); 20206e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay R1 = Op->getSourceRange(); 20219b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth return true; 20226e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay } 20239b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth 20249b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // Fallthrough for generic call handling. 20259b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth } 20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 20279fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case CXXMemberCallExprClass: 20289fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith case UserDefinedLiteralClass: { 2029026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 2030026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 2031d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 2032026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 2033026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 2034bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 2035bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 2036bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 2037bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 2038bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 2039a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2040bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 2041bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 2042bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 2043bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 2044bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 2045bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 2046bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 2047bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2048026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 2049026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 2050026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 205158beed91d468863b8c85bce43425422703838d27Anders Carlsson 205284c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay // If we don't know precisely what we're looking at, let's not warn. 205384c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case UnresolvedLookupExprClass: 205484c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay case CXXUnresolvedConstructExprClass: 205584c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay return false; 205684c3b9745f813a784b5d8ce77f2785750523d9ebMatt Beaumont-Gay 205758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 205858beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 205958beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 206058beed91d468863b8c85bce43425422703838d27Anders Carlsson 2061f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 2062f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 20634e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().ObjCAutoRefCount && 2064f85e193739c953358c865005855253af4f68a497John McCall ME->isInstanceMessage() && 2065f85e193739c953358c865005855253af4f68a497John McCall !ME->getType()->isVoidType() && 2066f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) && 2067f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) 2068f85e193739c953358c865005855253af4f68a497John McCall ->getName().startswith("init")) { 2069a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2070f85e193739c953358c865005855253af4f68a497John McCall Loc = getExprLoc(); 2071f85e193739c953358c865005855253af4f68a497John McCall R1 = ME->getSourceRange(); 2072f85e193739c953358c865005855253af4f68a497John McCall return true; 2073f85e193739c953358c865005855253af4f68a497John McCall } 2074f85e193739c953358c865005855253af4f68a497John McCall 2075f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 2076f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 2077a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2078f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 2079f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 2080f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 2081026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 2082f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 20831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 208412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 2085a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20865e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 20875e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 2088a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 208912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 20904b9c2d235fb9449e249d74f48ecfec601650de93John McCall case PseudoObjectExprClass: { 20914b9c2d235fb9449e249d74f48ecfec601650de93John McCall const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 20924b9c2d235fb9449e249d74f48ecfec601650de93John McCall 20934b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Only complain about things that have the form of a getter. 20944b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<UnaryOperator>(PO->getSyntacticForm()) || 20954b9c2d235fb9449e249d74f48ecfec601650de93John McCall isa<BinaryOperator>(PO->getSyntacticForm())) 20964b9c2d235fb9449e249d74f48ecfec601650de93John McCall return false; 20974b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2098a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 20994b9c2d235fb9449e249d74f48ecfec601650de93John McCall Loc = getExprLoc(); 21004b9c2d235fb9449e249d74f48ecfec601650de93John McCall R1 = getSourceRange(); 21014b9c2d235fb9449e249d74f48ecfec601650de93John McCall return true; 21024b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 21034b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2104611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 2105611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 2106611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 2107611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 2108611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 2109611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 2110611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 2111d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 2112611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 2113a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2114d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 2115d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 2116a6115068cde719142eb394db88612c185cabd05bEli Friedman return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2117d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21190faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 21200faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2121a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 2122026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 2123026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 2124026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 2125611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 21266319917b5021e9602389b49ca4f245d235e9b90aEli Friedman case CXXFunctionalCastExprClass: 2127a6115068cde719142eb394db88612c185cabd05bEli Friedman case CStyleCastExprClass: { 21284059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman // Ignore an explicit cast to void unless the operand is a non-trivial 2129a6115068cde719142eb394db88612c185cabd05bEli Friedman // volatile lvalue. 21304059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CastExpr *CE = cast<CastExpr>(this); 2131a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ToVoid) { 2132a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getSubExpr()->isGLValue() && 21334059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman CE->getSubExpr()->getType().isVolatileQualified()) { 21344059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const DeclRefExpr *DRE = 21354059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); 21364059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (!(DRE && isa<VarDecl>(DRE->getDecl()) && 21374059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { 21384059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, 21394059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1, R2, Ctx); 21404059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 21414059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 21420faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 2143a6115068cde719142eb394db88612c185cabd05bEli Friedman } 21444059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2145a6115068cde719142eb394db88612c185cabd05bEli Friedman // If this is a cast to a constructor conversion, check the operand. 214658beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 2147a6115068cde719142eb394db88612c185cabd05bEli Friedman if (CE->getCastKind() == CK_ConstructorConversion) 2148a6115068cde719142eb394db88612c185cabd05bEli Friedman return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 21494059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman 2150a6115068cde719142eb394db88612c185cabd05bEli Friedman WarnE = this; 21514059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman if (const CXXFunctionalCastExpr *CXXCE = 21524059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman dyn_cast<CXXFunctionalCastExpr>(this)) { 21534059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CXXCE->getTypeBeginLoc(); 21544059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CXXCE->getSubExpr()->getSourceRange(); 21554059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } else { 21564059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); 21574059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman Loc = CStyleCE->getLParenLoc(); 21584059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman R1 = CStyleCE->getSubExpr()->getSourceRange(); 21594059da87fa2fe9f415c9656dc63e75d5d4a489efEli Friedman } 2160026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 216158beed91d468863b8c85bce43425422703838d27Anders Carlsson } 2162a6115068cde719142eb394db88612c185cabd05bEli Friedman case ImplicitCastExprClass: { 2163a6115068cde719142eb394db88612c185cabd05bEli Friedman const CastExpr *ICE = cast<ImplicitCastExpr>(this); 2164a6115068cde719142eb394db88612c185cabd05bEli Friedman 2165a6115068cde719142eb394db88612c185cabd05bEli Friedman // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. 2166a6115068cde719142eb394db88612c185cabd05bEli Friedman if (ICE->getCastKind() == CK_LValueToRValue && 2167a6115068cde719142eb394db88612c185cabd05bEli Friedman ICE->getSubExpr()->getType().isVolatileQualified()) 2168a6115068cde719142eb394db88612c185cabd05bEli Friedman return false; 21694be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 2170a6115068cde719142eb394db88612c185cabd05bEli Friedman return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); 2171a6115068cde719142eb394db88612c185cabd05bEli Friedman } 217204421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 2173df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 2174a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 21764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 21774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 21784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 21794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 2180026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 21812d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 2182df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 2183a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21844765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 21854765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 2186a6115068cde719142eb394db88612c185cabd05bEli Friedman ->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); 21874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 219044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 21917f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 2192102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 2193f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 2194f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne switch (E->getStmtClass()) { 219544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 219644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 219744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 219844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 2199207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 2200f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 220144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 2202f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 220303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 220403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() 220503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isOBJCGCCandidate(Ctx); 220606b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 2207f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 2208a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 2209f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const Decl *D = cast<DeclRefExpr>(E)->getDecl(); 2210e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 2211102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 2212102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 2213102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 2214102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 221559a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 221659a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 22177e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 22180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 2219102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 222044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 222144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 222283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 2223f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const MemberExpr *M = cast<MemberExpr>(E); 2224102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 222544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 222644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 2227f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); 222844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 222944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 2230369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 223111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 223211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 223311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 22347eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 223511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 223611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 2237864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallQualType Expr::findBoundMemberType(const Expr *expr) { 2238e0a22d06888c13989b3f72db319f1d498bf69153John McCall assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); 2239864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2240864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Bound member expressions are always one of these possibilities: 2241864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // x->m x.m x->*y x.*y 2242864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // (possibly parenthesized) 2243864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2244864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall expr = expr->IgnoreParens(); 2245864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { 2246864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<CXXMethodDecl>(mem->getMemberDecl())); 2247864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return mem->getMemberDecl()->getType(); 2248864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2249864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2250864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { 2251864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() 2252864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ->getPointeeType(); 2253864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(type->isFunctionType()); 2254864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return type; 2255864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 2256864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 2257864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<UnresolvedMemberExpr>(expr)); 2258864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return QualType(); 2259864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 2260864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 22614e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 22624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 2263b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 2264b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 2265b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2266b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2267b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2268b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2269b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2270b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2271b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2272b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2273b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2274f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2275f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2276f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2277f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2278f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2279f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2280b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 2281b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 22824e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 22834e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 228456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 228556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 228656f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 228756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 228856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 2289b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 229056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2291b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2292b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2293b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 229456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2295b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2296b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2297b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2298b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2299b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2300b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2301b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2302b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2303f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2304f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2305f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2306f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2307f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2308f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 230903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 231003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 231103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 231203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 231303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2314c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2315c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2316c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2317c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2318c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2319b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 232056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 232156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 232256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 23239c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 23249c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 23259c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 23269c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 2327f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 2328f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 23299c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 2330f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2331f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2332f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 23339c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2334f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 2335f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2336f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2337f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 23389c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 23399c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 23409c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 23419c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 23429c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 2343f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2344f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2345f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2346f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2347f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 234803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (MaterializeTemporaryExpr *Materialize 234903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 235003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 235103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 2352c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } else if (SubstNonTypeTemplateParmExpr *NTTP 2353c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2354c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2355c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2356f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2357f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2358f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2359f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 2360f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2361632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2362632fbaa22fbed7c090eb83775731bfff786c2198Rafael EspindolaExpr *Expr::ignoreParenBaseCasts() { 2363632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola Expr *E = this; 2364632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola while (true) { 2365632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2366632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = P->getSubExpr(); 2367632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2368632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2369632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CastExpr *CE = dyn_cast<CastExpr>(E)) { 2370632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola if (CE->getCastKind() == CK_DerivedToBase || 2371632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_UncheckedDerivedToBase || 2372632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola CE->getCastKind() == CK_NoOp) { 2373632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola E = CE->getSubExpr(); 2374632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola continue; 2375632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2376632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2377632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 2378632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola return E; 2379632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 2380632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola} 2381632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 23822fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 23832fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 23842fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 2385b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 23862fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2387b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2388b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2389b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 23902fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2391b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2392b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2393b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2394b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2395b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2396b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2397b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2398b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2399f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2400f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2401f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2402f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2403f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2404f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 240503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 240603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 240703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 240803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 240903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2410c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2411c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2412c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2413c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2414c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2415b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 24162fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 24172fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 24182fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 24192f072b442879b8bba8c5dea11d7c61bedb1924aeHans WennborgExpr *Expr::IgnoreConversionOperator() { 24202f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { 242114d251cd62942bf7d56bb87a267ba2ca2f7fae3eChandler Carruth if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) 24222f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return MCE->getImplicitObjectArgument(); 24232f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 24242f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return this; 24252f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg} 24262f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 2427ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 2428ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 2429ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 2430ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 2431ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 2432ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 2433ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2434ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 2435ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2436ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2438ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2439ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 24402ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 2441ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2443ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 2444ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2445ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2446ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2448b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 24499d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 2450b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 24519d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 2452ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 2453ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2454ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2455ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2456ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2458b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2459b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2460b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2461b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2462b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2463b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2464b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 2465f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2466f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2467f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2468f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2469f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2470f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2471f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2472c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2473c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2474c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2475c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2476c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2477c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor 2478ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 2479ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2480ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 2481ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 24826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 24836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 248403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 248503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 248603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 24876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 24886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 2489c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 24906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 24916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 2492ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 24932f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 24942f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 2495f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 249603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 249703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 249803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 24992f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 25002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 25012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 25022f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 25032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 25042f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 25052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 25062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 25072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 25082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 25092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 25102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 25112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 25122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 25132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 25142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 2515f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 2516f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 25172f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 25182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2519558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 2520558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 2521558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 2522558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 2523558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 25242f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2525f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 25262f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 252758277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 2528db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 2529db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 253012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 2531db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 2532db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 25332f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 253419e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 253519e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 253619e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 253719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 2538558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 2539558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 2540558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 2541558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 2542558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 2543558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 2544558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 2545558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 25462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 25472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 254819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 254919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 255019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 255119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 255232f498a675df990901e6659d610dc740f9423228Eli Friedman if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) 255332f498a675df990901e6659d610dc740f9423228Eli Friedman if (BO->isPtrMemOp()) 255432f498a675df990901e6659d610dc740f9423228Eli Friedman return false; 255532f498a675df990901e6659d610dc740f9423228Eli Friedman 255656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 255756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 255856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 255956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2560558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 25612f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 25622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 256375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregorbool Expr::isImplicitCXXThis() const { 256475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor const Expr *E = this; 256575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 256675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // Strip away parentheses and casts we don't care about. 256775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor while (true) { 256875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { 256975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = Paren->getSubExpr(); 257075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 257175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 257275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 257375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 257475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (ICE->getCastKind() == CK_NoOp || 257575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_LValueToRValue || 257675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_DerivedToBase || 257775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_UncheckedDerivedToBase) { 257875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = ICE->getSubExpr(); 257975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 258075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 258375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { 258475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (UnOp->getOpcode() == UO_Extension) { 258575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = UnOp->getSubExpr(); 258675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 258775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 258975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 259003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M 259103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 259203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 259303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 259403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 259503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 259675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor break; 259775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 259875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 259975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) 260075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return This->isImplicit(); 260175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 260275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return false; 260375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 260475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 2605898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2606898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 2607cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkobool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) { 260813a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles for (unsigned I = 0; I < Exprs.size(); ++I) 2609898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2610898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2611898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2613898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2614898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 26154204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2616c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2617c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2618c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2619c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2620c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2621c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 26224204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 26234204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 26244204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 26254204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 26264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 26274204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 26284204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 26291f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2630e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2631c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 26324ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case IntegerLiteralClass: 26334ec4089b302d4ab2ec3deac089c7834d27aa39eeRichard Smith case FloatingLiteralClass: 2634e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 263514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2636eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2637e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2638b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2639b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2640b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 26414204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 26424204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 2643180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->getConstructor()->isTrivial()) { 2644180f47959a066795cc0f409433023af448bb0328Richard Smith // 1) an application of the trivial default constructor or 2645180f47959a066795cc0f409433023af448bb0328Richard Smith if (!CE->getNumArgs()) return true; 2646180f47959a066795cc0f409433023af448bb0328Richard Smith 2647180f47959a066795cc0f409433023af448bb0328Richard Smith // 2) an elidable trivial copy construction of an operand which is 2648180f47959a066795cc0f409433023af448bb0328Richard Smith // itself a constant initializer. Note that we consider the 2649180f47959a066795cc0f409433023af448bb0328Richard Smith // operand on its own, *not* as a reference binding. 2650180f47959a066795cc0f409433023af448bb0328Richard Smith if (CE->isElidable() && 2651180f47959a066795cc0f409433023af448bb0328Richard Smith CE->getArg(0)->isConstantInitializer(Ctx, false)) 2652180f47959a066795cc0f409433023af448bb0328Richard Smith return true; 2653180f47959a066795cc0f409433023af448bb0328Richard Smith } 2654180f47959a066795cc0f409433023af448bb0328Richard Smith 2655180f47959a066795cc0f409433023af448bb0328Richard Smith // 3) a foldable constexpr constructor. 2656180f47959a066795cc0f409433023af448bb0328Richard Smith break; 2657b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 265859b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 26591f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 26601f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 26611f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 266259b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 26634204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 266459b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2665e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 26661f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 26671f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 26681f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2669e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2670e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2671e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 26724204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2673e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2674e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2675c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2676e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 26773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 26783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 26793ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 26804204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 26814204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 2682f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2683f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2684f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return false; 2685f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr() 2686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ->isConstantInitializer(Ctx, IsForRef); 26875cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 26885cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 26895cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2690c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2691c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 26922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 26934204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2694c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2695c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 26964204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2697b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 269881045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2699d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith case CStyleCastExprClass: { 2700d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith const CastExpr *CE = cast<CastExpr>(this); 2701d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 27027a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // If we're promoting an integer to an _Atomic type then this is constant 27037a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // if the integer is constant. We also need to check the converse in case 27047a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // someone does something like: 27057a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 27067a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // int a = (_Atomic(int))42; 27077a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // 27087a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // I doubt anyone would write code like this directly, but it's quite 27097a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall // possible as the result of macro expansions. 27107a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (CE->getCastKind() == CK_NonAtomicToAtomic || 27117a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall CE->getCastKind() == CK_AtomicToNonAtomic) 27127a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return CE->getSubExpr()->isConstantInitializer(Ctx, false); 27137a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall 2714d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith // Handle bitcasts of vector constants. 2715d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith if (getType()->isVectorType() && CE->getCastKind() == CK_BitCast) 2716d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2717d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 27186bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // Handle misc casts we want to ignore. 27196bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman // FIXME: Is it really safe to ignore all these? 27206bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman if (CE->getCastKind() == CK_NoOp || 27216bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_LValueToRValue || 27226bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ToUnion || 27236bd9719fd97abac1b8126eae866e96db88be4ac8Eli Friedman CE->getCastKind() == CK_ConstructorConversion) 2724d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith return CE->getSubExpr()->isConstantInitializer(Ctx, false); 2725d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith 2726c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2727d62ca370b03b8c6ad58002d3399383baf744e32bRichard Smith } 272803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 27295f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() 273003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isConstantInitializer(Ctx, false); 2731e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2732c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 273338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 273438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 27358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smithbool Expr::HasSideEffects(const ASTContext &Ctx) const { 27368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (isInstantiationDependent()) 27378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 27388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith switch (getStmtClass()) { 27408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case NoStmtClass: 27418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define ABSTRACT_STMT(Type) 27428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define STMT(Type, Base) case Type##Class: 27438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #define EXPR(Type, Base) 27448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith #include "clang/AST/StmtNodes.inc" 27458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("unexpected Expr kind"); 27468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DependentScopeDeclRefExprClass: 27488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUnresolvedConstructExprClass: 27498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDependentScopeMemberExprClass: 27508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedLookupExprClass: 27518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnresolvedMemberExprClass: 27528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PackExpansionExprClass: 27538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmPackExprClass: 27549a4db032ecd991626d236a502e770126db32bd31Richard Smith case FunctionParmPackExprClass: 27558ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith llvm_unreachable("shouldn't see dependent / unresolved nodes here"); 27568ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 275760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case DeclRefExprClass: 275860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ObjCIvarRefExprClass: 27598ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PredefinedExprClass: 27608ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case IntegerLiteralClass: 27618ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case FloatingLiteralClass: 27628ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImaginaryLiteralClass: 27638ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StringLiteralClass: 27648ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CharacterLiteralClass: 27658ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OffsetOfExprClass: 27668ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ImplicitValueInitExprClass: 27678ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryExprOrTypeTraitExprClass: 27688ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AddrLabelExprClass: 27698ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GNUNullExprClass: 27708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBoolLiteralExprClass: 27718ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNullPtrLiteralExprClass: 27728ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThisExprClass: 27738ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXScalarValueInitExprClass: 27748ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case TypeTraitExprClass: 27758ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UnaryTypeTraitExprClass: 27768ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryTypeTraitExprClass: 27778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArrayTypeTraitExprClass: 27788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExpressionTraitExprClass: 27798ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNoexceptExprClass: 27808ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SizeOfPackExprClass: 27818ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCStringLiteralClass: 27828ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCEncodeExprClass: 27838ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoolLiteralExprClass: 27848ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXUuidofExprClass: 27858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case OpaqueValueExprClass: 27868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These never have a side-effect. 27878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 27888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 27898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CallExprClass: 27908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundAssignOperatorClass: 27918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case VAArgExprClass: 27928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AtomicExprClass: 27938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case StmtExprClass: 27948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXOperatorCallExprClass: 27958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXMemberCallExprClass: 27968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case UserDefinedLiteralClass: 27978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXThrowExprClass: 27988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXNewExprClass: 27998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDeleteExprClass: 28008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExprWithCleanupsClass: 28018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXBindTemporaryExprClass: 28028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BlockExprClass: 28038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CUDAKernelCallExprClass: 28048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These always have a side-effect. 28058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenExprClass: 28088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ArraySubscriptExprClass: 28098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MemberExprClass: 28108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ConditionalOperatorClass: 28118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryConditionalOperatorClass: 28128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CompoundLiteralExprClass: 28138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ExtVectorElementExprClass: 28148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case DesignatedInitExprClass: 28158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ParenListExprClass: 28168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXPseudoDestructorExprClass: 28178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case SubstNonTypeTemplateParmExprClass: 28188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case MaterializeTemporaryExprClass: 28198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ShuffleVectorExprClass: 28208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case AsTypeExprClass: 28218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // These have a side-effect if any subexpression does. 28228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 282460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case UnaryOperatorClass: 282560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) 28268ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28278ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case BinaryOperatorClass: 28308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<BinaryOperator>(this)->isAssignmentOp()) 28318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case InitListExprClass: 28358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: The children for an InitListExpr doesn't include the array filler. 28368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) 28378ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (E->HasSideEffects(Ctx)) 28388ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28398ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28408ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28418ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case GenericSelectionExprClass: 28428ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<GenericSelectionExpr>(this)->getResultExpr()-> 28438ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith HasSideEffects(Ctx); 28448ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28458ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ChooseExprClass: 28468ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->HasSideEffects(Ctx); 28478ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28488ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDefaultArgExprClass: 28498ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(Ctx); 28508ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28518ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXDynamicCastExprClass: { 28528ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // A dynamic_cast expression has side-effects if it can throw. 28538ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); 28548ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (DCE->getTypeAsWritten()->isReferenceType() && 28558ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith DCE->getCastKind() == CK_Dynamic) 28568ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 285760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith } // Fall through. 285860b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case ImplicitCastExprClass: 285960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CStyleCastExprClass: 286060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXStaticCastExprClass: 286160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXReinterpretCastExprClass: 286260b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXConstCastExprClass: 286360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith case CXXFunctionalCastExprClass: { 286460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith const CastExpr *CE = cast<CastExpr>(this); 286560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (CE->getCastKind() == CK_LValueToRValue && 286660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith CE->getSubExpr()->getType().isVolatileQualified()) 286760b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith return true; 28688ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28698ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28708ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28710d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith case CXXTypeidExprClass: 28720d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // typeid might throw if its subexpression is potentially-evaluated, so has 28730d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith // side-effects in that case whether or not its subexpression does. 28740d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); 28758ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28768ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXConstructExprClass: 28778ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case CXXTemporaryObjectExprClass: { 28788ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 287960b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith if (!CE->getConstructor()->isTrivial()) 28808ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 288160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // A trivial constructor does not add any side-effects of its own. Just look 288260b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith // at its arguments. 28838ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith break; 28848ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28858ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28868ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case LambdaExprClass: { 28878ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const LambdaExpr *LE = cast<LambdaExpr>(this); 28888ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (LambdaExpr::capture_iterator I = LE->capture_begin(), 28898ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = LE->capture_end(); I != E; ++I) 28908ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (I->getCaptureKind() == LCK_ByCopy) 28918ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Only has a side-effect if the variable is volatile or if 28928ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // the copy would invoke a non-trivial copy constructor. 28938ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 28948ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 28958ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 28968ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 28978ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case PseudoObjectExprClass: { 28988ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Only look for side-effects in the semantic form, and look past 28998ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // OpaqueValueExpr bindings in that form. 29008ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); 29018ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), 29028ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith E = PO->semantics_end(); 29038ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith I != E; ++I) { 29048ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith const Expr *Subexpr = *I; 29058ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) 29068ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith Subexpr = OVE->getSourceExpr(); 29078ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (Subexpr->HasSideEffects(Ctx)) 29088ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29098ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29108ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 29118ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29128ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29138ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBoxedExprClass: 29148ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCArrayLiteralClass: 29158ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCDictionaryLiteralClass: 29168ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCMessageExprClass: 29178ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSelectorExprClass: 29188ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCProtocolExprClass: 29198ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCPropertyRefExprClass: 29208ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIsaExprClass: 29218ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCIndirectCopyRestoreExprClass: 29228ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCSubscriptRefExprClass: 29238ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith case ObjCBridgedCastExprClass: 29248ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // FIXME: Classify these cases better. 29258ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29268ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith } 29278ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29288ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith // Recurse to children. 29298ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith for (const_child_range SubStmts = children(); SubStmts; ++SubStmts) 29308ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (const Stmt *S = *SubStmts) 29318ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith if (cast<Expr>(S)->HasSideEffects(Ctx)) 29328ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return true; 29338ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 29348ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith return false; 29358ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith} 29368ae4ec28451a16a57718286da3e476fc2f495c3fRichard Smith 293725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregornamespace { 293825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Look for a call to a non-trivial function within an expression. 293925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor class NonTrivialCallFinder : public EvaluatedExprVisitor<NonTrivialCallFinder> 294025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor { 294125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor typedef EvaluatedExprVisitor<NonTrivialCallFinder> Inherited; 294225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 294325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool NonTrivial; 294425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 294525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor public: 294625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor explicit NonTrivialCallFinder(ASTContext &Context) 2947b11e52540166a2958439cfe562c25931e4460759Douglas Gregor : Inherited(Context), NonTrivial(false) { } 294825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 294925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall() const { return NonTrivial; } 295025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 295125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCallExpr(CallExpr *E) { 295225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (CXXMethodDecl *Method 295325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor = dyn_cast_or_null<CXXMethodDecl>(E->getCalleeDecl())) { 295425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (Method->isTrivial()) { 295525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 295625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 295725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 295825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 295925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 296025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 296125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 296225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 296325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 296425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXConstructExpr(CXXConstructExpr *E) { 296525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getConstructor()->isTrivial()) { 296625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor // Recurse to children of the call. 296725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 296825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 296925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 297025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 297125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 297225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 297325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 297425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 297525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor if (E->getTemporary()->getDestructor()->isTrivial()) { 297625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Inherited::VisitStmt(E); 297725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return; 297825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 297925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 298025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivial = true; 298125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor } 298225d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor }; 298325d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 298425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 298525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregorbool Expr::hasNonTrivialCall(ASTContext &Ctx) { 298625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor NonTrivialCallFinder Finder(Ctx); 298725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor Finder.Visit(this); 298825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor return Finder.hasNonTrivialCall(); 298925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor} 299025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 299182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 299282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 299382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 299482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 299582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 299682214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 299782214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 299882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 2999ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 3000ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 3001ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 3002b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected value dependent expression!"); 3003ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 300482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 300550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 300682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 300782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 3008c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3009ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 301082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 3011ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 3012ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 3013f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 30140777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 30150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 30164e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) { 30170777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 30186217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 30190777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 30200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 30210777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 30220777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 3023ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 30240777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 30255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3026aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 3027aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 3028ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 3029aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 3030aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 3031aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 3032ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 3033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (const GenericSelectionExpr *GE = 3034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne dyn_cast<GenericSelectionExpr>(this)) { 3035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); 30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 30378123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 303804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 3039ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 30402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 30412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 304282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 304303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (const MaterializeTemporaryExpr *M 304403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(this)) { 304503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); 30464b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { 30474b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (const Expr *Source = OVE->getSourceExpr()) 30484b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Source->isNullPointerConstant(Ctx, NPC); 3049aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 30502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 30514e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith // C++11 nullptr_t is always a null pointer constant. 30526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 30534e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith return NPCK_CXX11_nullptr; 30546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 3055ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 3056ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 3057ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 3058ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 3059ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 3060ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 3061ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 3062aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 3063c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 30644e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType())) 306582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 306870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // test for the value 0. Don't use the C++11 constant expression semantics 306970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // for this, for now; once the dust settles on core issue 903, we might only 307070488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith // allow a literal 0 here in C++11 mode. 307180ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (Ctx.getLangOpts().CPlusPlus11) { 307270488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isCXX98IntegralConstantExpr(Ctx)) 307370488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 307470488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } else { 307570488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith if (!isIntegerConstantExpr(Ctx)) 307670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith return NPCK_NotNull; 307770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith } 307882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 307950800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (EvaluateKnownConstInt(Ctx) != 0) 308050800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_NotNull; 308150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie 308250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie if (isa<IntegerLiteral>(this)) 308350800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroLiteral; 308450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie return NPCK_ZeroExpression; 30855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 308631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 3087f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 3088f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 3089f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 3090f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 3091f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 3092f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 3093f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 3094f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 3095f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 3096f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 3097f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 3098f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 3099f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 3100f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3101f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3102f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3103f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 3104f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 3105f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3106f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 3107f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 3108f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 3109bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaksbool Expr::isObjCSelfExpr() const { 3110bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const Expr *E = IgnoreParenImpCasts(); 3111bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3112bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); 3113bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!DRE) 3114bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3115bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3116bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); 3117bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!Param) 3118bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3119bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3120bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); 3121bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks if (!M) 3122bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return false; 3123bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 3124bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks return M->getSelfDecl() == Param; 3125bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks} 3126bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 312733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 31286f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 312933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 3130de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 3131f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 3132f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 3133de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 3134de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 3135de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 3136de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 3137de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 313827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 313986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 314033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 314133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 314233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 31430f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 31440f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 31450f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 31460f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 31470f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 314842068e9d420889014ee26894e421fead336b239dEli Friedman if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { 314933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 315033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 315133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 315242068e9d420889014ee26894e421fead336b239dEli Friedman if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) 315342068e9d420889014ee26894e421fead336b239dEli Friedman return BinOp->getRHS()->getBitField(); 315442068e9d420889014ee26894e421fead336b239dEli Friedman } 315542068e9d420889014ee26894e421fead336b239dEli Friedman 315633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 315727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 315827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 3159093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 3160093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 3161c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3162093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 31635baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 31642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 3165093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 3166093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 3167093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 3168093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 3169c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3170093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 3171093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 3172093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3173093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 3174093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 3175093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 3176093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 3177093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 3178093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 31792140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 31802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 31812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 31822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 31832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 31842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 3185213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 3186183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 31878a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 31888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 31894d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 31904d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 31918a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 3192213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 3193a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 3194a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 31955f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 3196190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 3197190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 3198150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 3199190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3201190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 3202150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 3203150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3205150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 32065f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) 3207fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 3208150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 3209fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 3210fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 3211b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 32128a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 32133b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 32145f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<unsigned> &Elts) const { 32155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 32164b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 32174b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 32181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32194b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 32204b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 32214b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 32224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 32231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32248a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 32258a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 32261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32278a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 32288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 32298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 32308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 32318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 32328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 32338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 32348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 32358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 32364b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 3237b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 32383b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 3239b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 32408a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 32418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 324204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 324404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 324504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 324604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 324704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 3248c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3249207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3250207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 325104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32528d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3253746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3254746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3255f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 3256bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3257561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3258bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 325904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 326004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3261b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(IsInstanceSuper? SuperInstance : SuperClass), 3262746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3263746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SuperLoc(SuperLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 3264c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 3265207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 326604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 326704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 326804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 326904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 327104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 327204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3273f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3274207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3275207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 327604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 32778d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3278746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3279746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3280f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 3281561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isInstantiationDependentType(), 3282561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->containsUnexpandedParameterPack()), 328304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 328404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3285b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Class), 3286746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3287207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 328804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3289207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 329004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 329104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 329204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 329304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 3294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 329504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 329604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3297c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3298207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3299207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 330004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33018d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3302746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3303746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) 3304f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 3305bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 3306561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Receiver->isInstantiationDependent(), 3307bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 330804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 330904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 3310b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Instance), 3311746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), IsImplicit(isImplicit), 3312207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 331304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 3314207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 331504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 3316207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3317207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3318207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, 3319207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3320207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK) { 3321207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis setNumArgs(Args.size()); 3322aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 33238d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis for (unsigned I = 0; I != Args.size(); ++I) { 3324bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 3325bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3326bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 3327bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3328561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[I]->isInstantiationDependent()) 3329561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3330bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 3331bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3332bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3333bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 3334bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3335207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 333619562c97669532084a71895197f4444305dd432aBenjamin Kramer SelLocsKind = SelLocsK; 33370c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (!isImplicit()) { 33380c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis if (SelLocsK == SelLoc_NonStandard) 33390c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 33400c6b8e3fa718a0a67292340e5cff6fe7cbd15c14Argyrios Kyrtzidis } 334104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 334204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 334304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 334504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 334604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 334704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 334804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 3349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3350951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 335104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33528d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3353746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3354746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3355746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3356746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3357746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3358746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3359746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3360746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3361746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3362746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 3364207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SuperType, Sel, SelLocs, SelLocsK, 3365746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Method, Args, RBracLoc, isImplicit); 336604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 336704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 336804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 337004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 337104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 3372c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 3373951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 337404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33758d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3376746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3377746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3378746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3379746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3380746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3381746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3382746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3383746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3384746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3385746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3386951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3387746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3388746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 338904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 339004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 339104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 3392f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 339304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 339404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 3395f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 3396951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 339704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 33988d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3399746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 3400746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit) { 3401746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis assert((!SelLocs.empty() || isImplicit) && 3402746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis "No selector locs for non-implicit message"); 3403746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis ObjCMessageExpr *Mem; 3404746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelectorLocationsKind SelLocsK = SelectorLocationsKind(); 3405746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit) 3406746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args.size(), 0); 3407746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis else 3408746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 3409951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 3410746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc, 3411746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis isImplicit); 341204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 341304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 3414c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 3415207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3416207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3417207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); 341804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 341904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 3420e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3421207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3422207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 3423207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 3424207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 3425207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 3426207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK) { 3427207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); 3428207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() 3429207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis : 0; 3430207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return alloc(C, Args.size(), NumStoredSelLocs); 3431207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3432207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3433207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 3434207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 3435207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 3436207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 3437207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); 3438207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (ObjCMessageExpr *)C.Allocate(Size, 3439207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::AlignOf<ObjCMessageExpr>::Alignment); 3440207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3441207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3442207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::getSelectorLocs( 3443207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVectorImpl<SourceLocation> &SelLocs) const { 3444207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 3445207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs.push_back(getSelectorLoc(i)); 3446207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 3447207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 3448e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 3449e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 3450e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 3451e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 3452e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3453e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 3454e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 3455e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 3456e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 3457e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 3458e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 3459e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 3460e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 34613026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid ReceiverKind!"); 3462e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 3463e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 346404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 346504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 346604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 346704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 3468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 346904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 347004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 3471e4a990f34904eb572c8d6aa1deef19465214359cArgyrios KyrtzidisQualType ObjCMessageExpr::getReceiverType() const { 347204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 347304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 3474e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getInstanceReceiver()->getType(); 347504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 3476e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getClassReceiver(); 347704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 347804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 3479e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return getSuperType(); 348004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 34810389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 3482e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis llvm_unreachable("unexpected receiver kind"); 3483e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis} 3484e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3485e4a990f34904eb572c8d6aa1deef19465214359cArgyrios KyrtzidisObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 3486e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis QualType T = getReceiverType(); 3487e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3488e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis if (const ObjCObjectPointerType *Ptr = T->getAs<ObjCObjectPointerType>()) 3489e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return Ptr->getInterfaceDecl(); 3490e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 3491e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis if (const ObjCObjectType *Ty = T->getAs<ObjCObjectType>()) 3492e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis return Ty->getInterface(); 3493e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 349404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 3495eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 34960389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 34975f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef ObjCBridgedCastExpr::getBridgeKindName() const { 3498f85e193739c953358c865005855253af4f68a497John McCall switch (getBridgeKind()) { 3499f85e193739c953358c865005855253af4f68a497John McCall case OBC_Bridge: 3500f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 3501f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeTransfer: 3502f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_transfer"; 3503f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeRetained: 3504f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_retained"; 3505f85e193739c953358c865005855253af4f68a497John McCall } 35063026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie 35073026348bd4c13a0f83b59839f64065e0fcbea253David Blaikie llvm_unreachable("Invalid BridgeKind!"); 3508f85e193739c953358c865005855253af4f68a497John McCall} 3509f85e193739c953358c865005855253af4f68a497John McCall 35104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 3511a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getCond()->EvaluateKnownConstInt(C) != 0; 351227437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 351327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 35143b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, 3515bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 3516bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 3517bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 3518bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 3519561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 3520bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 35213b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) 3522bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 35233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs = new (C) Stmt*[args.size()]; 35243b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 3525bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 3526bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3527bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 3528bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3529561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 3530561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3531bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 3532bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3533bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3534bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 3535bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 3536bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 3537bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 3538888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 3539888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 3540888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 3541888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3542888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 354394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 354494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 35451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 3546888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 3547f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3548f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 35493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 35503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 35513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3552f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3553f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3554f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex) 3555f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3556f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getType(), 3557f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getValueKind(), 3558f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getObjectKind(), 3559f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isTypeDependent(), 3560f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isValueDependent(), 3561561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor AssocExprs[ResultIndex]->isInstantiationDependent(), 3562f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 35633b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 35643b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 35653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), 35663b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3567f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 35683b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 35693b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 35703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3571f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3572f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3573f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3574f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 35753b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 35763b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 35773b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, 3578f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3579f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack) 3580f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3581f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Context.DependentTy, 3582f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne VK_RValue, 3583f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne OK_Ordinary, 3584561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isTypeDependent=*/true, 3585561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isValueDependent=*/true, 3586561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isInstantiationDependent=*/true, 3587f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 35883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), 35893b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), 35903b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc), 35913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { 3592f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 35933b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(AssocTypes.size() == AssocExprs.size()); 35943b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); 35953b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); 3596f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3597f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 359877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 359905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 360005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 360105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3602b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler CarruthIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 360705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 360905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3610c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 3611319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 3612ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 36131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 3614ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 36153b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 36169ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 36171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 3618f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 3619bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 3620561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Init->isInstantiationDependent(), 3621bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 36221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 36233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumDesignators(NumDesignators), NumSubExprs(IndexExprs.size() + 1) { 3624319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 36259ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 36277502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 36289ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 36299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 36319ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 36329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 36339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 3634ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 36359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 36379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 36389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 3639bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 3640bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3641561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Index->isInstantiationDependent()) 3642561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3643bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3644bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 3645bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 36469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 36489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 36509ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 36519ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 36529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 3653bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 3654561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isTypeDependent() || End->isValueDependent()) { 3655bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3656561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3657561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (Start->isInstantiationDependent() || 3658561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isInstantiationDependent()) { 3659561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3660561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 3661561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3662bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3663bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 3664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 3665bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 36669ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36679ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 36689ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 36709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 36719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 36729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 36733b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); 3674ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3675ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 367605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 36771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 367805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 36793b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 368005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 3682c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 36833b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer sizeof(Stmt *) * (IndexExprs.size() + 1), 8); 3684319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 36859ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 36863b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer IndexExprs, Init); 368705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 368805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 3690d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 3691d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3692d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3693d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 3694d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3695d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3696319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 3697319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 3698d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 3699319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 3700d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 3701d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 3702d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 3703d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3704d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 370524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo BagnaraSourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { 370624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); 370724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara if (size() == 1) 370824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return DIE->getDesignator(0)->getSourceRange(); 370965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceRange(DIE->getDesignator(0)->getLocStart(), 371065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen DIE->getDesignator(size()-1)->getLocEnd()); 371124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara} 371224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 371365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation DesignatedInitExpr::getLocStart() const { 371405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 3715d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 3716d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 371705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 3718eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 371905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 372005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 372105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 372205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 3723d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 3724d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 372565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return StartLoc; 372665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen} 372765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 372865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik VerbruggenSourceLocation DesignatedInitExpr::getLocEnd() const { 372965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getInit()->getLocEnd(); 373005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 373705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 37411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 374205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 37501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 375305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 375405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 375505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 375605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 375705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3758ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 3759ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 3760319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 37611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 3762ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 3763ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 3764ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 3765ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 3766ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 3767ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 3768ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 3769ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3770ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 3771ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 3772ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3773ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 3774ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 37751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 3776319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 3777ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 3778ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 3779ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 3780ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 3781ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 3782ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 3783ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3784ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 37851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 37863b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, 37875b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation rparenloc) 37885b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 3789561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, false, false), 37903b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) { 37913b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer Exprs = new (C) Stmt*[exprs.size()]; 37923b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != exprs.size(); ++i) { 3793bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 3794bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3795bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 3796bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3797561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (exprs[i]->isInstantiationDependent()) 3798561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3799bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 3800bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3801bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 38022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 3803bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 38042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 38052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 3806e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 3807e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 3808e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 380903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) 381003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor e = m->GetTemporaryExpr(); 3811e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 3812e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 3813e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 3814e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 3815e996ffd240f20a1048179d7727a6ee3227261921John McCall} 3816e996ffd240f20a1048179d7727a6ee3227261921John McCall 38174b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &Context, EmptyShell sh, 38184b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs) { 38194b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = Context.Allocate(sizeof(PseudoObjectExpr) + 38204b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + numSemanticExprs) * sizeof(Expr*), 38214b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 38224b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); 38234b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38254b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) 38264b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, shell) { 38274b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; 38284b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38294b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38304b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr *PseudoObjectExpr::Create(ASTContext &C, Expr *syntax, 38314b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantics, 38324b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) { 38334b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(syntax && "no syntactic expression!"); 38344b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics.size() && "no semantic expressions!"); 38354b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38364b9c2d235fb9449e249d74f48ecfec601650de93John McCall QualType type; 38374b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprValueKind VK; 38384b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (resultIndex == NoResult) { 38394b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = C.VoidTy; 38404b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = VK_RValue; 38414b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 38424b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(resultIndex < semantics.size()); 38434b9c2d235fb9449e249d74f48ecfec601650de93John McCall type = semantics[resultIndex]->getType(); 38444b9c2d235fb9449e249d74f48ecfec601650de93John McCall VK = semantics[resultIndex]->getValueKind(); 38454b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); 38464b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 38474b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38484b9c2d235fb9449e249d74f48ecfec601650de93John McCall void *buffer = C.Allocate(sizeof(PseudoObjectExpr) + 38494b9c2d235fb9449e249d74f48ecfec601650de93John McCall (1 + semantics.size()) * sizeof(Expr*), 38504b9c2d235fb9449e249d74f48ecfec601650de93John McCall llvm::alignOf<PseudoObjectExpr>()); 38514b9c2d235fb9449e249d74f48ecfec601650de93John McCall return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, 38524b9c2d235fb9449e249d74f48ecfec601650de93John McCall resultIndex); 38534b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38544b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38554b9c2d235fb9449e249d74f48ecfec601650de93John McCallPseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, 38564b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntax, ArrayRef<Expr*> semantics, 38574b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex) 38584b9c2d235fb9449e249d74f48ecfec601650de93John McCall : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, 38594b9c2d235fb9449e249d74f48ecfec601650de93John McCall /*filled in at end of ctor*/ false, false, false, false) { 38604b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; 38614b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExprBits.ResultIndex = resultIndex + 1; 38624b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38634b9c2d235fb9449e249d74f48ecfec601650de93John McCall for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { 38644b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *E = (i == 0 ? syntax : semantics[i-1]); 38654b9c2d235fb9449e249d74f48ecfec601650de93John McCall getSubExprsBuffer()[i] = E; 38664b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38674b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isTypeDependent()) 38684b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.TypeDependent = true; 38694b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isValueDependent()) 38704b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ValueDependent = true; 38714b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->isInstantiationDependent()) 38724b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.InstantiationDependent = true; 38734b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (E->containsUnexpandedParameterPack()) 38744b9c2d235fb9449e249d74f48ecfec601650de93John McCall ExprBits.ContainsUnexpandedParameterPack = true; 38754b9c2d235fb9449e249d74f48ecfec601650de93John McCall 38764b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<OpaqueValueExpr>(E)) 38774b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != 0 && 38784b9c2d235fb9449e249d74f48ecfec601650de93John McCall "opaque-value semantic expressions for pseudo-object " 38794b9c2d235fb9449e249d74f48ecfec601650de93John McCall "operations must have sources"); 38804b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 38814b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 38824b9c2d235fb9449e249d74f48ecfec601650de93John McCall 388305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 3884ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 3885ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 3886ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3887ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 3888ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 3889ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 3890ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 3891ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 3892ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 3893ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 3894ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 3895ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3896ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 389777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 389877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 389977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 3900f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne// UnaryExprOrTypeTraitExpr 3901f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneStmt::child_range UnaryExprOrTypeTraitExpr::children() { 39020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 39030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 39040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 39050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 3906f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 39070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 390863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 390963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 39100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 391163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 39129ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 3913390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3914563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 391563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 391663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 391704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 391863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 391963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 392063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 392163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 392263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 3923563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 3924563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 3925cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri GribenkoObjCArrayLiteral::ObjCArrayLiteral(ArrayRef<Expr *> Elements, 3926ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *Method, 3927ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3928ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, T, VK_RValue, OK_Ordinary, 3929ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false, false, false), 3930ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) 3931ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3932ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **SaveElements = getElements(); 3933ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = Elements.size(); I != N; ++I) { 3934ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isTypeDependent() || Elements[I]->isValueDependent()) 3935ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3936ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->isInstantiationDependent()) 3937ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3938ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Elements[I]->containsUnexpandedParameterPack()) 3939ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3940ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3941ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SaveElements[I] = Elements[I]; 3942ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3943ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3944ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3945ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::Create(ASTContext &C, 3946cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<Expr *> Elements, 3947ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 3948ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 3949ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3950ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + Elements.size() * sizeof(Expr *)); 3951ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR); 3952ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3953ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3954ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(ASTContext &C, 3955ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 3956ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3957ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCArrayLiteral) 3958ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek + NumElements * sizeof(Expr *)); 3959ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); 3960ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3961ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3962ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::ObjCDictionaryLiteral( 3963ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 3964ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 3965ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 3966ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) 3967ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 3968ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), 3969ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), 3970ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek DictWithObjectsMethod(method) 3971ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek{ 3972ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *KeyValues = getKeyValues(); 3973ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *Expansions = getExpansionData(); 3974ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I < NumElements; I++) { 3975ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() || 3976ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent()) 3977ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ValueDependent = true; 3978ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].Key->isInstantiationDependent() || 3979ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->isInstantiationDependent()) 3980ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.InstantiationDependent = true; 3981ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].EllipsisLoc.isInvalid() && 3982ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (VK[I].Key->containsUnexpandedParameterPack() || 3983ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek VK[I].Value->containsUnexpandedParameterPack())) 3984ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprBits.ContainsUnexpandedParameterPack = true; 3985ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3986ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Key = VK[I].Key; 3987ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValues[I].Value = VK[I].Value; 3988ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansions) { 3989ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].EllipsisLoc = VK[I].EllipsisLoc; 3990ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (VK[I].NumExpansions) 3991ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = *VK[I].NumExpansions + 1; 3992ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek else 3993ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expansions[I].NumExpansionsPlusOne = 0; 3994ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3995ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 3996ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 3997ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3998ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 3999ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::Create(ASTContext &C, 4000ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 4001ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 4002ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 4003ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR) { 4004ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 4005ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 4006ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * VK.size(); 4007ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4008ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 4009ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * VK.size() + ExpansionsSize); 4010ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR); 4011ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4012ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4013ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral * 4014ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCDictionaryLiteral::CreateEmpty(ASTContext &C, unsigned NumElements, 4015ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) { 4016ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned ExpansionsSize = 0; 4017ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) 4018ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionsSize = sizeof(ExpansionData) * NumElements; 4019ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + 4020ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek sizeof(KeyValuePair) * NumElements + ExpansionsSize); 4021ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCDictionaryLiteral(EmptyShell(), NumElements, 4022ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions); 4023ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4024ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 4025ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekObjCSubscriptRefExpr *ObjCSubscriptRefExpr::Create(ASTContext &C, 4026ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 4027ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 4028ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 4029ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 4030ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB) { 4031ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr)); 4032ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return new (Mem) ObjCSubscriptRefExpr(base, key, T, VK_LValue, 4033ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OK_ObjCSubscript, 4034ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getMethod, setMethod, RB); 4035ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 4036dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 40373b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin KramerAtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, 4038dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType t, AtomicOp op, SourceLocation RP) 4039dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, 4040dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman false, false, false, false), 40413b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) 4042dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman{ 40433b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); 40443b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer for (unsigned i = 0; i != args.size(); i++) { 4045dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isTypeDependent()) 4046dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.TypeDependent = true; 4047dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isValueDependent()) 4048dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ValueDependent = true; 4049dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->isInstantiationDependent()) 4050dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.InstantiationDependent = true; 4051dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (args[i]->containsUnexpandedParameterPack()) 4052dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprBits.ContainsUnexpandedParameterPack = true; 4053dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4054dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs[i] = args[i]; 4055dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 4056dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman} 4057e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4058e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smithunsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { 4059e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith switch (Op) { 4060ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_init: 4061ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_load: 4062ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load_n: 4063e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 2; 4064ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4065ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_store: 4066ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_exchange: 4067ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_load: 4068ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store: 4069ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_store_n: 4070ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange_n: 4071ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_add: 4072ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_sub: 4073ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_and: 4074ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_or: 4075ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_fetch_xor: 4076ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_add: 4077ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_sub: 4078ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_and: 4079ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_or: 4080ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_fetch_xor: 408151b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_fetch_nand: 4082ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_add_fetch: 4083ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_sub_fetch: 4084ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_and_fetch: 4085ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_or_fetch: 4086ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_xor_fetch: 408751b92401c9f95023a2ef27064fd5a60fd99175f5Richard Smith case AO__atomic_nand_fetch: 4088e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 3; 4089ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4090ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_exchange: 4091ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 4; 4092ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4093ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_strong: 4094ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__c11_atomic_compare_exchange_weak: 4095e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith return 5; 4096ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4097ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange: 4098ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith case AO__atomic_compare_exchange_n: 4099ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return 6; 4100e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith } 4101e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith llvm_unreachable("unknown atomic op"); 4102e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith} 4103