<br><br><div class="gmail_quote">On Mon, Feb 18, 2013 at 11:06 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: dblaikie<br>
Date: Mon Feb 18 16:06:02 2013<br>
New Revision: 175462<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=175462&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=175462&view=rev</a><br>
Log:<br>
Replace TypeLoc llvm::cast support to be well-defined.<br>
<br>
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined<br>
behavior by casting pointers/references to TypeLoc objects to derived types<br>
and then using the derived copy constructors (or even returning pointers to<br>
derived types that actually point to the original TypeLoc object).<br>
<br>
Some context is in this thread:<br>
<a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html</a><br>
Though it's spread over a few months which can be hard to read in the mail<br>
archive.<br>
<br></blockquote><div><br>Great to see that cleanup patch landing!<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Modified:<br>
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
cfe/trunk/include/clang/AST/TypeLoc.h<br>
cfe/trunk/include/clang/AST/TypeLocVisitor.h<br>
cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp<br>
cfe/trunk/lib/AST/ASTContext.cpp<br>
cfe/trunk/lib/AST/Comment.cpp<br>
cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
cfe/trunk/lib/AST/TemplateBase.cpp<br>
cfe/trunk/lib/AST/TypeLoc.cpp<br>
cfe/trunk/lib/Sema/SemaChecking.cpp<br>
cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/lib/Sema/SemaDeclAttr.cpp<br>
cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaInit.cpp<br>
cfe/trunk/lib/Sema/SemaStmt.cpp<br>
cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp<br>
cfe/trunk/lib/Sema/SemaType.cpp<br>
cfe/trunk/lib/Sema/TreeTransform.h<br>
cfe/trunk/lib/Sema/TypeLocBuilder.h<br>
cfe/trunk/tools/libclang/CIndex.cpp<br>
cfe/trunk/tools/libclang/CXCursor.cpp<br>
cfe/trunk/tools/libclang/IndexingContext.cpp<br>
cfe/trunk/tools/libclang/RecursiveASTVisitor.h<br>
<br>
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)<br>
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Feb 18 16:06:02 2013<br>
@@ -594,7 +594,7 @@ bool RecursiveASTVisitor<Derived>::Trave<br>
#define ABSTRACT_TYPELOC(CLASS, BASE)<br>
#define TYPELOC(CLASS, BASE) \<br>
case TypeLoc::CLASS: \<br>
- return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL));<br>
+ return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());<br>
#include "clang/AST/TypeLocNodes.def"<br>
}<br>
<br>
@@ -2100,8 +2100,7 @@ bool RecursiveASTVisitor<Derived>::Trave<br>
if (S->hasExplicitParameters() && S->hasExplicitResultType()) {<br>
// Visit the whole type.<br>
TRY_TO(TraverseTypeLoc(TL));<br>
- } else if (isa<FunctionProtoTypeLoc>(TL)) {<br>
- FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);<br>
+ } else if (FunctionProtoTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) {<br>
if (S->hasExplicitParameters()) {<br>
// Visit parameters.<br>
for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I) {<br>
<br>
Modified: cfe/trunk/include/clang/AST/TypeLoc.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)<br>
+++ cfe/trunk/include/clang/AST/TypeLoc.h Mon Feb 18 16:06:02 2013<br>
@@ -44,6 +44,28 @@ protected:<br>
void *Data;<br>
<br>
public:<br>
+ template<typename T><br>
+ T castAs() const {<br>
+ assert(T::isType(this));<br>
+ T t;<br>
+ TypeLoc& tl = t;<br>
+ tl = *this;<br>
+ return t;<br>
+ }<br>
+ template<typename T><br>
+ T getAs() const {<br>
+ if (!T::isType(this))<br>
+ return T();<br>
+ T t;<br>
+ TypeLoc& tl = t;<br>
+ tl = *this;<br>
+ return t;<br>
+ }<br>
+<br>
+ static bool isType(const TypeLoc*) {<br>
+ return true;<br>
+ }<br>
+<br>
/// The kinds of TypeLocs. Equivalent to the Type::TypeClass enum,<br>
/// except it also defines a Qualified enum that corresponds to the<br>
/// QualifiedLoc class.<br>
@@ -119,11 +141,7 @@ public:<br>
/// \brief Skips past any qualifiers, if this is qualified.<br>
UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header<br>
<br>
- TypeLoc IgnoreParens() const {<br>
- if (isa<ParenTypeLoc>(this))<br>
- return IgnoreParensImpl(*this);<br>
- return *this;<br>
- }<br>
+ TypeLoc IgnoreParens() const;<br>
<br>
/// \brief Initializes this to state that every location in this<br>
/// type is the given location.<br>
@@ -187,7 +205,9 @@ public:<br>
return (TypeLocClass) getTypePtr()->getTypeClass();<br>
}<br>
<br>
- static bool classof(const TypeLoc *TL) {<br>
+private:<br>
+ friend class TypeLoc;<br>
+ static bool isType(const TypeLoc *TL) {<br>
return !TL->getType().hasLocalQualifiers();<br>
}<br>
};<br>
@@ -231,15 +251,17 @@ public:<br>
getFullDataSizeForType(getType().getLocalUnqualifiedType());<br>
}<br>
<br>
- static bool classof(const TypeLoc *TL) {<br>
+private:<br>
+ friend class TypeLoc;<br>
+ static bool isType(const TypeLoc *TL) {<br>
return TL->getType().hasLocalQualifiers();<br>
}<br>
};<br>
<br>
inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {<br>
- if (isa<QualifiedTypeLoc>(this))<br>
- return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();<br>
- return cast<UnqualTypeLoc>(*this);<br>
+ if (QualifiedTypeLoc Loc = getAs<QualifiedTypeLoc>())<br>
+ return Loc.getUnqualifiedLoc();<br>
+ return castAs<UnqualTypeLoc>();<br>
}<br>
<br>
/// A metaprogramming base class for TypeLoc classes which correspond<br>
@@ -280,24 +302,22 @@ class ConcreteTypeLoc : public Base {<br>
return static_cast<const Derived*>(this);<br>
}<br>
<br>
-public:<br>
- unsigned getLocalDataSize() const {<br>
- return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();<br>
- }<br>
- // Give a default implementation that's useful for leaf types.<br>
- unsigned getFullDataSize() const {<br>
- return asDerived()->getLocalDataSize() + getInnerTypeSize();<br>
+ friend class TypeLoc;<br>
+ static bool isType(const TypeLoc *TL) {<br>
+ return Derived::classofType(TL->getTypePtr());<br>
}<br>
<br>
static bool classofType(const Type *Ty) {<br>
return TypeClass::classof(Ty);<br>
}<br>
<br>
- static bool classof(const TypeLoc *TL) {<br>
- return Derived::classofType(TL->getTypePtr());<br>
+public:<br>
+ unsigned getLocalDataSize() const {<br>
+ return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();<br>
}<br>
- static bool classof(const UnqualTypeLoc *TL) {<br>
- return Derived::classofType(TL->getTypePtr());<br>
+ // Give a default implementation that's useful for leaf types.<br>
+ unsigned getFullDataSize() const {<br>
+ return asDerived()->getLocalDataSize() + getInnerTypeSize();<br>
}<br>
<br>
TypeLoc getNextTypeLoc() const {<br>
@@ -362,18 +382,19 @@ private:<br>
/// information. See the note on ConcreteTypeLoc.<br>
template <class Base, class Derived, class TypeClass><br>
class InheritingConcreteTypeLoc : public Base {<br>
-public:<br>
+ friend class TypeLoc;<br>
static bool classofType(const Type *Ty) {<br>
return TypeClass::classof(Ty);<br>
}<br>
<br>
- static bool classof(const TypeLoc *TL) {<br>
+ static bool isType(const TypeLoc *TL) {<br>
return Derived::classofType(TL->getTypePtr());<br>
}<br>
- static bool classof(const UnqualTypeLoc *TL) {<br>
+ static bool isType(const UnqualTypeLoc *TL) {<br>
return Derived::classofType(TL->getTypePtr());<br>
}<br>
<br>
+public:<br>
const TypeClass *getTypePtr() const {<br>
return cast<TypeClass>(Base::getTypePtr());<br>
}<br>
@@ -406,7 +427,9 @@ public:<br>
setNameLoc(Loc);<br>
}<br>
<br>
- static bool classof(const TypeLoc *TL);<br>
+private:<br>
+ friend class TypeLoc;<br>
+ static bool isType(const TypeLoc *TL);<br>
};<br>
<br>
<br>
@@ -899,6 +922,11 @@ public:<br>
}<br>
};<br>
<br>
+inline TypeLoc TypeLoc::IgnoreParens() const {<br>
+ if (ParenTypeLoc::isType(this))<br>
+ return IgnoreParensImpl(*this);<br>
+ return *this;<br>
+}<br>
<br>
struct PointerLikeLocInfo {<br>
SourceLocation StarLoc;<br>
<br>
Modified: cfe/trunk/include/clang/AST/TypeLocVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocVisitor.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocVisitor.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/TypeLocVisitor.h (original)<br>
+++ cfe/trunk/include/clang/AST/TypeLocVisitor.h Mon Feb 18 16:06:02 2013<br>
@@ -21,7 +21,7 @@ namespace clang {<br>
<br>
#define DISPATCH(CLASSNAME) \<br>
return static_cast<ImplClass*>(this)-> \<br>
- Visit##CLASSNAME(cast<CLASSNAME>(TyLoc))<br>
+ Visit##CLASSNAME(TyLoc.castAs<CLASSNAME>())<br>
<br>
template<typename ImplClass, typename RetTy=void><br>
class TypeLocVisitor {<br>
<br>
Modified: cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp (original)<br>
+++ cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp Mon Feb 18 16:06:02 2013<br>
@@ -63,19 +63,18 @@ public:<br>
return;<br>
TypeLoc TL = TInfo->getTypeLoc();<br>
while (TL) {<br>
- if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL)) {<br>
- TL = QL->getUnqualifiedLoc();<br>
- } else if (const AttributedTypeLoc *<br>
- Attr = dyn_cast<AttributedTypeLoc>(&TL)) {<br>
- if (handleAttr(*Attr, D))<br>
+ if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>()) {<br>
+ TL = QL.getUnqualifiedLoc();<br>
+ } else if (AttributedTypeLoc Attr = TL.getAs<AttributedTypeLoc>()) {<br>
+ if (handleAttr(Attr, D))<br>
break;<br>
- TL = Attr->getModifiedLoc();<br>
- } else if (const ArrayTypeLoc *Arr = dyn_cast<ArrayTypeLoc>(&TL)) {<br>
- TL = Arr->getElementLoc();<br>
- } else if (const PointerTypeLoc *PT = dyn_cast<PointerTypeLoc>(&TL)) {<br>
- TL = PT->getPointeeLoc();<br>
- } else if (const ReferenceTypeLoc *RT = dyn_cast<ReferenceTypeLoc>(&TL))<br>
- TL = RT->getPointeeLoc();<br>
+ TL = Attr.getModifiedLoc();<br>
+ } else if (ArrayTypeLoc Arr = TL.getAs<ArrayTypeLoc>()) {<br>
+ TL = Arr.getElementLoc();<br>
+ } else if (PointerTypeLoc PT = TL.getAs<PointerTypeLoc>()) {<br>
+ TL = PT.getPointeeLoc();<br>
+ } else if (ReferenceTypeLoc RT = TL.getAs<ReferenceTypeLoc>())<br>
+ TL = RT.getPointeeLoc();<br>
else<br>
break;<br>
}<br>
@@ -249,8 +248,9 @@ static void checkAllAtProps(MigrationCon<br>
if (!TInfo)<br>
return;<br>
TypeLoc TL = TInfo->getTypeLoc();<br>
- if (AttributedTypeLoc *ATL = dyn_cast<AttributedTypeLoc>(&TL)) {<br>
- ATLs.push_back(std::make_pair(*ATL, PD));<br>
+ if (AttributedTypeLoc ATL =<br>
+ TL.getAs<AttributedTypeLoc>()) {<br>
+ ATLs.push_back(std::make_pair(ATL, PD));<br>
if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {<br>
hasWeak = true;<br>
} else if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong)<br>
<br>
Modified: cfe/trunk/lib/AST/ASTContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTContext.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Feb 18 16:06:02 2013<br>
@@ -2957,8 +2957,8 @@ ASTContext::getTemplateSpecializationTyp<br>
QualType TST = getTemplateSpecializationType(Name, Args, Underlying);<br>
<br>
TypeSourceInfo *DI = CreateTypeSourceInfo(TST);<br>
- TemplateSpecializationTypeLoc TL<br>
- = cast<TemplateSpecializationTypeLoc>(DI->getTypeLoc());<br>
+ TemplateSpecializationTypeLoc TL =<br>
+ DI->getTypeLoc().castAs<TemplateSpecializationTypeLoc>();<br>
TL.setTemplateKeywordLoc(SourceLocation());<br>
TL.setTemplateNameLoc(NameLoc);<br>
TL.setLAngleLoc(Args.getLAngleLoc());<br>
<br>
Modified: cfe/trunk/lib/AST/Comment.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Comment.cpp (original)<br>
+++ cfe/trunk/lib/AST/Comment.cpp Mon Feb 18 16:06:02 2013<br>
@@ -241,32 +241,32 @@ void DeclInfo::fill() {<br>
while (true) {<br>
TL = TL.IgnoreParens();<br>
// Look through qualified types.<br>
- if (QualifiedTypeLoc *QualifiedTL = dyn_cast<QualifiedTypeLoc>(&TL)) {<br>
- TL = QualifiedTL->getUnqualifiedLoc();<br>
+ if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>()) {<br>
+ TL = QualifiedTL.getUnqualifiedLoc();<br>
continue;<br>
}<br>
// Look through pointer types.<br>
- if (PointerTypeLoc *PointerTL = dyn_cast<PointerTypeLoc>(&TL)) {<br>
- TL = PointerTL->getPointeeLoc().getUnqualifiedLoc();<br>
+ if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>()) {<br>
+ TL = PointerTL.getPointeeLoc().getUnqualifiedLoc();<br>
continue;<br>
}<br>
- if (BlockPointerTypeLoc *BlockPointerTL =<br>
- dyn_cast<BlockPointerTypeLoc>(&TL)) {<br>
- TL = BlockPointerTL->getPointeeLoc().getUnqualifiedLoc();<br>
+ if (BlockPointerTypeLoc BlockPointerTL =<br>
+ TL.getAs<BlockPointerTypeLoc>()) {<br>
+ TL = BlockPointerTL.getPointeeLoc().getUnqualifiedLoc();<br>
continue;<br>
}<br>
- if (MemberPointerTypeLoc *MemberPointerTL =<br>
- dyn_cast<MemberPointerTypeLoc>(&TL)) {<br>
- TL = MemberPointerTL->getPointeeLoc().getUnqualifiedLoc();<br>
+ if (MemberPointerTypeLoc MemberPointerTL =<br>
+ TL.getAs<MemberPointerTypeLoc>()) {<br>
+ TL = MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();<br>
continue;<br>
}<br>
// Is this a typedef for a function type?<br>
- if (FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL)) {<br>
+ if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {<br>
Kind = FunctionKind;<br>
- ArrayRef<ParmVarDecl *> Params = FTL->getParams();<br>
+ ArrayRef<ParmVarDecl *> Params = FTL.getParams();<br>
ParamVars = ArrayRef<const ParmVarDecl *>(Params.data(),<br>
Params.size());<br>
- ResultType = FTL->getResultLoc().getType();<br>
+ ResultType = FTL.getResultLoc().getType();<br>
break;<br>
}<br>
break;<br>
<br>
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)<br>
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Feb 18 16:06:02 2013<br>
@@ -396,7 +396,7 @@ isTemplate(const NamedDecl *ND,<br>
TypeSourceInfo *TSI = Spec->getTypeAsWritten();<br>
if (TSI) {<br>
TemplateSpecializationTypeLoc TSTL =<br>
- cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());<br>
+ TSI->getTypeLoc().castAs<TemplateSpecializationTypeLoc>();<br>
TemplateArgumentListInfo LI(TSTL.getLAngleLoc(), TSTL.getRAngleLoc());<br>
for (unsigned i = 0, e = TSTL.getNumArgs(); i != e; ++i)<br>
TemplateArgs.push_back(TSTL.getArgLoc(i));<br>
<br>
Modified: cfe/trunk/lib/AST/TemplateBase.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)<br>
+++ cfe/trunk/lib/AST/TemplateBase.cpp Mon Feb 18 16:06:02 2013<br>
@@ -466,8 +466,8 @@ TemplateArgumentLoc::getPackExpansionPat<br>
ExpansionTSInfo = Context.getTrivialTypeSourceInfo(<br>
getArgument().getAsType(),<br>
Ellipsis);<br>
- PackExpansionTypeLoc Expansion<br>
- = cast<PackExpansionTypeLoc>(ExpansionTSInfo->getTypeLoc());<br>
+ PackExpansionTypeLoc Expansion =<br>
+ ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();<br>
Ellipsis = Expansion.getEllipsisLoc();<br>
<br>
TypeLoc Pattern = Expansion.getPatternLoc();<br>
<br>
Modified: cfe/trunk/lib/AST/TypeLoc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)<br>
+++ cfe/trunk/lib/AST/TypeLoc.cpp Mon Feb 18 16:06:02 2013<br>
@@ -86,7 +86,7 @@ void TypeLoc::initializeImpl(ASTContext<br>
#define ABSTRACT_TYPELOC(CLASS, PARENT)<br>
#define TYPELOC(CLASS, PARENT) \<br>
case CLASS: { \<br>
- CLASS##TypeLoc TLCasted = cast<CLASS##TypeLoc>(TL); \<br>
+ CLASS##TypeLoc TLCasted = TL.castAs<CLASS##TypeLoc>(); \<br>
TLCasted.initializeLocal(Context, Loc); \<br>
TL = TLCasted.getNextTypeLoc(); \<br>
if (!TL) return; \<br>
@@ -106,7 +106,8 @@ SourceLocation TypeLoc::getBeginLoc() co<br>
LeftMost = Cur;<br>
break;<br>
case FunctionProto:<br>
- if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn()) {<br>
+ if (Cur.castAs<FunctionProtoTypeLoc>().getTypePtr()<br>
+ ->hasTrailingReturn()) {<br>
LeftMost = Cur;<br>
break;<br>
}<br>
@@ -151,7 +152,7 @@ SourceLocation TypeLoc::getEndLoc() cons<br>
Last = Cur;<br>
break;<br>
case FunctionProto:<br>
- if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn())<br>
+ if (Cur.castAs<FunctionProtoTypeLoc>().getTypePtr()->hasTrailingReturn())<br>
Last = TypeLoc();<br>
else<br>
Last = Cur;<br>
@@ -198,7 +199,7 @@ namespace {<br>
/// because it's a convenient base class. Ideally we would not accept<br>
/// those here, but ideally we would have better implementations for<br>
/// them.<br>
-bool TypeSpecTypeLoc::classof(const TypeLoc *TL) {<br>
+bool TypeSpecTypeLoc::isType(const TypeLoc *TL) {<br>
if (TL->getType().hasLocalQualifiers()) return false;<br>
return TSTChecker().Visit(*TL);<br>
}<br>
@@ -278,8 +279,8 @@ TypeSpecifierType BuiltinTypeLoc::getWri<br>
}<br>
<br>
TypeLoc TypeLoc::IgnoreParensImpl(TypeLoc TL) {<br>
- while (ParenTypeLoc* PTL = dyn_cast<ParenTypeLoc>(&TL))<br>
- TL = PTL->getInnerLoc();<br>
+ while (ParenTypeLoc PTL = TL.getAs<ParenTypeLoc>())<br>
+ TL = PTL.getInnerLoc();<br>
return TL;<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Feb 18 16:06:02 2013<br>
@@ -5772,14 +5772,13 @@ static bool IsTailPaddedMemberArray(Sema<br>
while (TInfo) {<br>
TypeLoc TL = TInfo->getTypeLoc();<br>
// Look through typedefs.<br>
- const TypedefTypeLoc *TTL = dyn_cast<TypedefTypeLoc>(&TL);<br>
- if (TTL) {<br>
- const TypedefNameDecl *TDL = TTL->getTypedefNameDecl();<br>
+ if (TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>()) {<br>
+ const TypedefNameDecl *TDL = TTL.getTypedefNameDecl();<br>
TInfo = TDL->getTypeSourceInfo();<br>
continue;<br>
}<br>
- if (const ConstantArrayTypeLoc *CTL = dyn_cast<ConstantArrayTypeLoc>(&TL)) {<br>
- const Expr *SizeExpr = dyn_cast<IntegerLiteral>(CTL->getSizeExpr());<br>
+ if (ConstantArrayTypeLoc CTL = TL.getAs<ConstantArrayTypeLoc>()) {<br>
+ const Expr *SizeExpr = dyn_cast<IntegerLiteral>(CTL.getSizeExpr());<br>
if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())<br>
return false;<br>
}<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Feb 18 16:06:02 2013<br>
@@ -2147,36 +2147,35 @@ static std::string FormatFunctionParamet<br>
<br>
// The argument for a block pointer parameter is a block literal with<br>
// the appropriate type.<br>
- FunctionTypeLoc *Block = 0;<br>
- FunctionProtoTypeLoc *BlockProto = 0;<br>
+ FunctionTypeLoc Block;<br>
+ FunctionProtoTypeLoc BlockProto;<br>
TypeLoc TL;<br>
if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) {<br>
TL = TSInfo->getTypeLoc().getUnqualifiedLoc();<br>
while (true) {<br>
// Look through typedefs.<br>
if (!SuppressBlock) {<br>
- if (TypedefTypeLoc *TypedefTL = dyn_cast<TypedefTypeLoc>(&TL)) {<br>
- if (TypeSourceInfo *InnerTSInfo<br>
- = TypedefTL->getTypedefNameDecl()->getTypeSourceInfo()) {<br>
+ if (TypedefTypeLoc TypedefTL = TL.getAs<TypedefTypeLoc>()) {<br>
+ if (TypeSourceInfo *InnerTSInfo =<br>
+ TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) {<br>
TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc();<br>
continue;<br>
}<br>
}<br>
<br>
// Look through qualified types<br>
- if (QualifiedTypeLoc *QualifiedTL = dyn_cast<QualifiedTypeLoc>(&TL)) {<br>
- TL = QualifiedTL->getUnqualifiedLoc();<br>
+ if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>()) {<br>
+ TL = QualifiedTL.getUnqualifiedLoc();<br>
continue;<br>
}<br>
}<br>
<br>
// Try to get the function prototype behind the block pointer type,<br>
// then we're done.<br>
- if (BlockPointerTypeLoc *BlockPtr<br>
- = dyn_cast<BlockPointerTypeLoc>(&TL)) {<br>
- TL = BlockPtr->getPointeeLoc().IgnoreParens();<br>
- Block = dyn_cast<FunctionTypeLoc>(&TL);<br>
- BlockProto = dyn_cast<FunctionProtoTypeLoc>(&TL);<br>
+ if (BlockPointerTypeLoc BlockPtr = TL.getAs<BlockPointerTypeLoc>()) {<br>
+ TL = BlockPtr.getPointeeLoc().IgnoreParens();<br>
+ Block = TL.getAs<FunctionTypeLoc>();<br>
+ BlockProto = TL.getAs<FunctionProtoTypeLoc>();<br>
}<br>
break;<br>
}<br>
@@ -2204,27 +2203,27 @@ static std::string FormatFunctionParamet<br>
// We have the function prototype behind the block pointer type, as it was<br>
// written in the source.<br>
std::string Result;<br>
- QualType ResultType = Block->getTypePtr()->getResultType();<br>
+ QualType ResultType = Block.getTypePtr()->getResultType();<br>
if (!ResultType->isVoidType() || SuppressBlock)<br>
ResultType.getAsStringInternal(Result, Policy);<br>
<br>
// Format the parameter list.<br>
std::string Params;<br>
- if (!BlockProto || Block->getNumArgs() == 0) {<br>
- if (BlockProto && BlockProto->getTypePtr()->isVariadic())<br>
+ if (!BlockProto || Block.getNumArgs() == 0) {<br>
+ if (BlockProto && BlockProto.getTypePtr()->isVariadic())<br>
Params = "(...)";<br>
else<br>
Params = "(void)";<br>
} else {<br>
Params += "(";<br>
- for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {<br>
+ for (unsigned I = 0, N = Block.getNumArgs(); I != N; ++I) {<br>
if (I)<br>
Params += ", ";<br>
- Params += FormatFunctionParameter(Context, Policy, Block->getArg(I),<br>
+ Params += FormatFunctionParameter(Context, Policy, Block.getArg(I),<br>
/*SuppressName=*/false,<br>
/*SuppressBlock=*/true);<br>
<br>
- if (I == N - 1 && BlockProto->getTypePtr()->isVariadic())<br>
+ if (I == N - 1 && BlockProto.getTypePtr()->isVariadic())<br>
Params += ", ...";<br>
}<br>
Params += ")";<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 18 16:06:02 2013<br>
@@ -4066,29 +4066,29 @@ static QualType TryToFixInvalidVariablyM<br>
<br>
static void<br>
FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL) {<br>
- if (PointerTypeLoc* SrcPTL = dyn_cast<PointerTypeLoc>(&SrcTL)) {<br>
- PointerTypeLoc* DstPTL = cast<PointerTypeLoc>(&DstTL);<br>
- FixInvalidVariablyModifiedTypeLoc(SrcPTL->getPointeeLoc(),<br>
- DstPTL->getPointeeLoc());<br>
- DstPTL->setStarLoc(SrcPTL->getStarLoc());<br>
+ if (PointerTypeLoc SrcPTL = SrcTL.getAs<PointerTypeLoc>()) {<br>
+ PointerTypeLoc DstPTL = DstTL.castAs<PointerTypeLoc>();<br>
+ FixInvalidVariablyModifiedTypeLoc(SrcPTL.getPointeeLoc(),<br>
+ DstPTL.getPointeeLoc());<br>
+ DstPTL.setStarLoc(SrcPTL.getStarLoc());<br>
return;<br>
}<br>
- if (ParenTypeLoc* SrcPTL = dyn_cast<ParenTypeLoc>(&SrcTL)) {<br>
- ParenTypeLoc* DstPTL = cast<ParenTypeLoc>(&DstTL);<br>
- FixInvalidVariablyModifiedTypeLoc(SrcPTL->getInnerLoc(),<br>
- DstPTL->getInnerLoc());<br>
- DstPTL->setLParenLoc(SrcPTL->getLParenLoc());<br>
- DstPTL->setRParenLoc(SrcPTL->getRParenLoc());<br>
+ if (ParenTypeLoc SrcPTL = SrcTL.getAs<ParenTypeLoc>()) {<br>
+ ParenTypeLoc DstPTL = DstTL.castAs<ParenTypeLoc>();<br>
+ FixInvalidVariablyModifiedTypeLoc(SrcPTL.getInnerLoc(),<br>
+ DstPTL.getInnerLoc());<br>
+ DstPTL.setLParenLoc(SrcPTL.getLParenLoc());<br>
+ DstPTL.setRParenLoc(SrcPTL.getRParenLoc());<br>
return;<br>
}<br>
- ArrayTypeLoc* SrcATL = cast<ArrayTypeLoc>(&SrcTL);<br>
- ArrayTypeLoc* DstATL = cast<ArrayTypeLoc>(&DstTL);<br>
- TypeLoc SrcElemTL = SrcATL->getElementLoc();<br>
- TypeLoc DstElemTL = DstATL->getElementLoc();<br>
+ ArrayTypeLoc SrcATL = SrcTL.castAs<ArrayTypeLoc>();<br>
+ ArrayTypeLoc DstATL = DstTL.castAs<ArrayTypeLoc>();<br>
+ TypeLoc SrcElemTL = SrcATL.getElementLoc();<br>
+ TypeLoc DstElemTL = DstATL.getElementLoc();<br>
DstElemTL.initializeFullCopy(SrcElemTL);<br>
- DstATL->setLBracketLoc(SrcATL->getLBracketLoc());<br>
- DstATL->setSizeExpr(SrcATL->getSizeExpr());<br>
- DstATL->setRBracketLoc(SrcATL->getRBracketLoc());<br>
+ DstATL.setLBracketLoc(SrcATL.getLBracketLoc());<br>
+ DstATL.setSizeExpr(SrcATL.getSizeExpr());<br>
+ DstATL.setRBracketLoc(SrcATL.getRBracketLoc());<br>
}<br>
<br>
/// Helper method to turn variable array types into constant array<br>
@@ -6600,12 +6600,12 @@ static SourceRange getResultSourceRange(<br>
return SourceRange();<br>
<br>
TypeLoc TL = TSI->getTypeLoc();<br>
- FunctionTypeLoc *FunctionTL = dyn_cast<FunctionTypeLoc>(&TL);<br>
+ FunctionTypeLoc FunctionTL = TL.getAs<FunctionTypeLoc>();<br>
if (!FunctionTL)<br>
return SourceRange();<br>
<br>
- TypeLoc ResultTL = FunctionTL->getResultLoc();<br>
- if (isa<BuiltinTypeLoc>(ResultTL.getUnqualifiedLoc()))<br>
+ TypeLoc ResultTL = FunctionTL.getResultLoc();<br>
+ if (ResultTL.getUnqualifiedLoc().getAs<BuiltinTypeLoc>())<br>
return ResultTL.getSourceRange();<br>
<br>
return SourceRange();<br>
@@ -8291,11 +8291,11 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop<br>
// but that could be a zero-parameter prototype<br>
TypeSourceInfo* TI = PossibleZeroParamPrototype->getTypeSourceInfo();<br>
TypeLoc TL = TI->getTypeLoc();<br>
- if (FunctionNoProtoTypeLoc* FTL = dyn_cast<FunctionNoProtoTypeLoc>(&TL))<br>
+ if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())<br>
Diag(PossibleZeroParamPrototype->getLocation(),<br>
diag::note_declaration_not_a_prototype)<br>
<< PossibleZeroParamPrototype<br>
- << FixItHint::CreateInsertion(FTL->getRParenLoc(), "void");<br>
+ << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");<br>
}<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Feb 18 16:06:02 2013<br>
@@ -3715,10 +3715,10 @@ static void handleGlobalAttr(Sema &S, De<br>
FunctionDecl *FD = cast<FunctionDecl>(D);<br>
if (!FD->getResultType()->isVoidType()) {<br>
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc().IgnoreParens();<br>
- if (FunctionTypeLoc* FTL = dyn_cast<FunctionTypeLoc>(&TL)) {<br>
+ if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {<br>
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)<br>
<< FD->getType()<br>
- << FixItHint::CreateReplacement(FTL->getResultLoc().getSourceRange(),<br>
+ << FixItHint::CreateReplacement(FTL.getResultLoc().getSourceRange(),<br>
"void");<br>
} else {<br>
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Feb 18 16:06:02 2013<br>
@@ -3757,7 +3757,7 @@ struct CheckAbstractUsage {<br>
switch (TL.getTypeLocClass()) {<br>
#define ABSTRACT_TYPELOC(CLASS, PARENT)<br>
#define TYPELOC(CLASS, PARENT) \<br>
- case TypeLoc::CLASS: Check(cast<CLASS##TypeLoc>(TL), Sel); break;<br>
+ case TypeLoc::CLASS: Check(TL.castAs<CLASS##TypeLoc>(), Sel); break;<br>
#include "clang/AST/TypeLocNodes.def"<br>
}<br>
}<br>
@@ -10432,15 +10432,16 @@ Decl *Sema::ActOnTemplatedFriendTag(Scop<br>
<br>
TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);<br>
if (isa<DependentNameType>(T)) {<br>
- DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());<br>
+ DependentNameTypeLoc TL =<br>
+ TSI->getTypeLoc().castAs<DependentNameTypeLoc>();<br>
TL.setElaboratedKeywordLoc(TagLoc);<br>
TL.setQualifierLoc(QualifierLoc);<br>
TL.setNameLoc(NameLoc);<br>
} else {<br>
- ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(TSI->getTypeLoc());<br>
+ ElaboratedTypeLoc TL = TSI->getTypeLoc().castAs<ElaboratedTypeLoc>();<br>
TL.setElaboratedKeywordLoc(TagLoc);<br>
TL.setQualifierLoc(QualifierLoc);<br>
- cast<TypeSpecTypeLoc>(TL.getNamedTypeLoc()).setNameLoc(NameLoc);<br>
+ TL.getNamedTypeLoc().castAs<TypeSpecTypeLoc>().setNameLoc(NameLoc);<br>
}<br>
<br>
FriendDecl *Friend = FriendDecl::Create(Context, CurContext, NameLoc,<br>
@@ -10460,7 +10461,7 @@ Decl *Sema::ActOnTemplatedFriendTag(Scop<br>
ElaboratedTypeKeyword ETK = TypeWithKeyword::getKeywordForTagTypeKind(Kind);<br>
QualType T = Context.getDependentNameType(ETK, SS.getScopeRep(), Name);<br>
TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);<br>
- DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());<br>
+ DependentNameTypeLoc TL = TSI->getTypeLoc().castAs<DependentNameTypeLoc>();<br>
TL.setElaboratedKeywordLoc(TagLoc);<br>
TL.setQualifierLoc(SS.getWithLocInContext(Context));<br>
TL.setNameLoc(NameLoc);<br>
@@ -11538,7 +11539,7 @@ bool Sema::checkThisInStaticMemberFuncti<br>
return false;<br>
<br>
TypeLoc TL = TSInfo->getTypeLoc();<br>
- FunctionProtoTypeLoc *ProtoTL = dyn_cast<FunctionProtoTypeLoc>(&TL);<br>
+ FunctionProtoTypeLoc ProtoTL = TL.getAs<FunctionProtoTypeLoc>();<br>
if (!ProtoTL)<br>
return false;<br>
<br>
@@ -11549,12 +11550,12 @@ bool Sema::checkThisInStaticMemberFuncti<br>
// within a static member function as they are within a non-static member<br>
// function). [ Note: this is because declaration matching does not occur<br>
// until the complete declarator is known. - end note ]<br>
- const FunctionProtoType *Proto = ProtoTL->getTypePtr();<br>
+ const FunctionProtoType *Proto = ProtoTL.getTypePtr();<br>
FindCXXThisExpr Finder(*this);<br>
<br>
// If the return type came after the cv-qualifier-seq, check it now.<br>
if (Proto->hasTrailingReturn() &&<br>
- !Finder.TraverseTypeLoc(ProtoTL->getResultLoc()))<br>
+ !Finder.TraverseTypeLoc(ProtoTL.getResultLoc()))<br>
return true;<br>
<br>
// Check the exception specification.<br>
@@ -11570,11 +11571,11 @@ bool Sema::checkThisInStaticMemberFuncti<br>
return false;<br>
<br>
TypeLoc TL = TSInfo->getTypeLoc();<br>
- FunctionProtoTypeLoc *ProtoTL = dyn_cast<FunctionProtoTypeLoc>(&TL);<br>
+ FunctionProtoTypeLoc ProtoTL = TL.getAs<FunctionProtoTypeLoc>();<br>
if (!ProtoTL)<br>
return false;<br>
<br>
- const FunctionProtoType *Proto = ProtoTL->getTypePtr();<br>
+ const FunctionProtoType *Proto = ProtoTL.getTypePtr();<br>
FindCXXThisExpr Finder(*this);<br>
<br>
switch (Proto->getExceptionSpecType()) {<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Mon Feb 18 16:06:02 2013<br>
@@ -294,8 +294,8 @@ bool Sema::CheckEquivalentExceptionSpec(<br>
SourceLocation FixItLoc;<br>
if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) {<br>
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();<br>
- if (const FunctionTypeLoc *FTLoc = dyn_cast<FunctionTypeLoc>(&TL))<br>
- FixItLoc = PP.getLocForEndOfToken(FTLoc->getLocalRangeEnd());<br>
+ if (FunctionTypeLoc FTLoc = TL.getAs<FunctionTypeLoc>())<br>
+ FixItLoc = PP.getLocForEndOfToken(FTLoc.getLocalRangeEnd());<br>
}<br>
<br>
if (FixItLoc.isInvalid())<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb 18 16:06:02 2013<br>
@@ -3836,9 +3836,9 @@ bool Sema::GatherArgumentsForCall(Source<br>
<br>
static void DiagnoseCalleeStaticArrayParam(Sema &S, ParmVarDecl *PVD) {<br>
TypeLoc TL = PVD->getTypeSourceInfo()->getTypeLoc();<br>
- if (ArrayTypeLoc *ATL = dyn_cast<ArrayTypeLoc>(&TL))<br>
+ if (ArrayTypeLoc ATL = TL.getAs<ArrayTypeLoc>())<br>
S.Diag(PVD->getLocation(), diag::note_callee_static_array)<br>
- << ATL->getLocalSourceRange();<br>
+ << ATL.getLocalSourceRange();<br>
}<br>
<br>
/// CheckStaticArrayArgument - If the given argument corresponds to a static<br>
@@ -9437,8 +9437,7 @@ void Sema::ActOnBlockArguments(SourceLoc<br>
FunctionProtoTypeLoc ExplicitSignature;<br>
<br>
TypeLoc tmp = Sig->getTypeLoc().IgnoreParens();<br>
- if (isa<FunctionProtoTypeLoc>(tmp)) {<br>
- ExplicitSignature = cast<FunctionProtoTypeLoc>(tmp);<br>
+ if ((ExplicitSignature = tmp.getAs<FunctionProtoTypeLoc>())) {<br>
<br>
// Check whether that explicit signature was synthesized by<br>
// GetTypeForDeclarator. If so, don't save that as part of the<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaInit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Feb 18 16:06:02 2013<br>
@@ -4899,9 +4899,9 @@ InitializationSequence::Perform(Sema &S,<br>
if (DeclaratorDecl *DD = Entity.getDecl()) {<br>
if (TypeSourceInfo *TInfo = DD->getTypeSourceInfo()) {<br>
TypeLoc TL = TInfo->getTypeLoc();<br>
- if (IncompleteArrayTypeLoc *ArrayLoc<br>
- = dyn_cast<IncompleteArrayTypeLoc>(&TL))<br>
- Brackets = ArrayLoc->getBracketsRange();<br>
+ if (IncompleteArrayTypeLoc ArrayLoc =<br>
+ TL.getAs<IncompleteArrayTypeLoc>())<br>
+ Brackets = ArrayLoc.getBracketsRange();<br>
}<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Feb 18 16:06:02 2013<br>
@@ -237,7 +237,7 @@ void Sema::DiagnoseUnusedExprResult(cons<br>
<br>
// We really do want to use the non-canonical type here.<br>
if (T == Context.VoidPtrTy) {<br>
- PointerTypeLoc TL = cast<PointerTypeLoc>(TI->getTypeLoc());<br>
+ PointerTypeLoc TL = TI->getTypeLoc().castAs<PointerTypeLoc>();<br>
<br>
Diag(Loc, diag::warn_unused_voidptr)<br>
<< FixItHint::CreateRemoval(TL.getStarLoc());<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Feb 18 16:06:02 2013<br>
@@ -6956,15 +6956,15 @@ Sema::ActOnTypenameType(Scope *S, Source<br>
<br>
TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);<br>
if (isa<DependentNameType>(T)) {<br>
- DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());<br>
+ DependentNameTypeLoc TL = TSI->getTypeLoc().castAs<DependentNameTypeLoc>();<br>
TL.setElaboratedKeywordLoc(TypenameLoc);<br>
TL.setQualifierLoc(QualifierLoc);<br>
TL.setNameLoc(IdLoc);<br>
} else {<br>
- ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(TSI->getTypeLoc());<br>
+ ElaboratedTypeLoc TL = TSI->getTypeLoc().castAs<ElaboratedTypeLoc>();<br>
TL.setElaboratedKeywordLoc(TypenameLoc);<br>
TL.setQualifierLoc(QualifierLoc);<br>
- cast<TypeSpecTypeLoc>(TL.getNamedTypeLoc()).setNameLoc(IdLoc);<br>
+ TL.getNamedTypeLoc().castAs<TypeSpecTypeLoc>().setNameLoc(IdLoc);<br>
}<br>
<br>
return CreateParsedType(T, TSI);<br>
@@ -7054,12 +7054,12 @@ static bool isEnableIf(NestedNameSpecifi<br>
if (!NNS || !NNS.getNestedNameSpecifier()->getAsType())<br>
return false;<br>
TypeLoc EnableIfTy = NNS.getTypeLoc();<br>
- TemplateSpecializationTypeLoc *EnableIfTSTLoc =<br>
- dyn_cast<TemplateSpecializationTypeLoc>(&EnableIfTy);<br>
- if (!EnableIfTSTLoc || EnableIfTSTLoc->getNumArgs() == 0)<br>
+ TemplateSpecializationTypeLoc EnableIfTSTLoc =<br>
+ EnableIfTy.getAs<TemplateSpecializationTypeLoc>();<br>
+ if (!EnableIfTSTLoc || EnableIfTSTLoc.getNumArgs() == 0)<br>
return false;<br>
const TemplateSpecializationType *EnableIfTST =<br>
- cast<TemplateSpecializationType>(EnableIfTSTLoc->getTypePtr());<br>
+ cast<TemplateSpecializationType>(EnableIfTSTLoc.getTypePtr());<br>
<br>
// ... which names a complete class template declaration...<br>
const TemplateDecl *EnableIfDecl =<br>
@@ -7074,7 +7074,7 @@ static bool isEnableIf(NestedNameSpecifi<br>
return false;<br>
<br>
// Assume the first template argument is the condition.<br>
- CondRange = EnableIfTSTLoc->getArgLoc(0).getSourceRange();<br>
+ CondRange = EnableIfTSTLoc.getArgLoc(0).getSourceRange();<br>
return true;<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Feb 18 16:06:02 2013<br>
@@ -1566,10 +1566,10 @@ static bool NeedsInstantiationAsFunction<br>
return true;<br>
<br>
TypeLoc TL = T->getTypeLoc().IgnoreParens();<br>
- if (!isa<FunctionProtoTypeLoc>(TL))<br>
+ if (!TL.getAs<FunctionProtoTypeLoc>())<br>
return false;<br>
<br>
- FunctionProtoTypeLoc FP = cast<FunctionProtoTypeLoc>(TL);<br>
+ FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>();<br>
for (unsigned I = 0, E = FP.getNumArgs(); I != E; ++I) {<br>
ParmVarDecl *P = FP.getArg(I);<br>
<br>
@@ -1613,9 +1613,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclT<br>
TLB.reserve(TL.getFullDataSize());<br>
<br>
QualType Result;<br>
-<br>
- if (FunctionProtoTypeLoc *Proto = dyn_cast<FunctionProtoTypeLoc>(&TL)) {<br>
- Result = Instantiator.TransformFunctionProtoType(TLB, *Proto, ThisContext,<br>
+<br>
+ if (FunctionProtoTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) {<br>
+ Result = Instantiator.TransformFunctionProtoType(TLB, Proto, ThisContext,<br>
ThisTypeQuals);<br>
} else {<br>
Result = Instantiator.TransformType(TLB, TL);<br>
@@ -1635,9 +1635,8 @@ ParmVarDecl *Sema::SubstParmVarDecl(Parm<br>
TypeSourceInfo *NewDI = 0;<br>
<br>
TypeLoc OldTL = OldDI->getTypeLoc();<br>
- if (isa<PackExpansionTypeLoc>(OldTL)) {<br>
- PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(OldTL);<br>
-<br>
+ if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) {<br>
+<br>
// We have a function parameter pack. Substitute into the pattern of the<br>
// expansion.<br>
NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Feb 18 16:06:02 2013<br>
@@ -1706,7 +1706,7 @@ Decl *TemplateDeclInstantiator::VisitNon<br>
// The non-type template parameter pack's type is a pack expansion of types.<br>
// Determine whether we need to expand this parameter pack into separate<br>
// types.<br>
- PackExpansionTypeLoc Expansion = cast<PackExpansionTypeLoc>(TL);<br>
+ PackExpansionTypeLoc Expansion = TL.castAs<PackExpansionTypeLoc>();<br>
TypeLoc Pattern = Expansion.getPatternLoc();<br>
SmallVector<UnexpandedParameterPack, 2> Unexpanded;<br>
SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);<br>
@@ -2335,15 +2335,14 @@ TemplateDeclInstantiator::SubstFunctionT<br>
if (NewTInfo != OldTInfo) {<br>
// Get parameters from the new type info.<br>
TypeLoc OldTL = OldTInfo->getTypeLoc().IgnoreParens();<br>
- if (FunctionProtoTypeLoc *OldProtoLoc<br>
- = dyn_cast<FunctionProtoTypeLoc>(&OldTL)) {<br>
+ if (FunctionProtoTypeLoc OldProtoLoc =<br>
+ OldTL.getAs<FunctionProtoTypeLoc>()) {<br>
TypeLoc NewTL = NewTInfo->getTypeLoc().IgnoreParens();<br>
- FunctionProtoTypeLoc *NewProtoLoc = cast<FunctionProtoTypeLoc>(&NewTL);<br>
- assert(NewProtoLoc && "Missing prototype?");<br>
+ FunctionProtoTypeLoc NewProtoLoc = NewTL.castAs<FunctionProtoTypeLoc>();<br>
unsigned NewIdx = 0;<br>
- for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc->getNumArgs();<br>
+ for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumArgs();<br>
OldIdx != NumOldParams; ++OldIdx) {<br>
- ParmVarDecl *OldParam = OldProtoLoc->getArg(OldIdx);<br>
+ ParmVarDecl *OldParam = OldProtoLoc.getArg(OldIdx);<br>
LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;<br>
<br>
llvm::Optional<unsigned> NumArgumentsInExpansion;<br>
@@ -2354,14 +2353,14 @@ TemplateDeclInstantiator::SubstFunctionT<br>
if (!NumArgumentsInExpansion) {<br>
// Simple case: normal parameter, or a parameter pack that's<br>
// instantiated to a (still-dependent) parameter pack.<br>
- ParmVarDecl *NewParam = NewProtoLoc->getArg(NewIdx++);<br>
+ ParmVarDecl *NewParam = NewProtoLoc.getArg(NewIdx++);<br>
Params.push_back(NewParam);<br>
Scope->InstantiatedLocal(OldParam, NewParam);<br>
} else {<br>
// Parameter pack expansion: make the instantiation an argument pack.<br>
Scope->MakeInstantiatedLocalArgPack(OldParam);<br>
for (unsigned I = 0; I != *NumArgumentsInExpansion; ++I) {<br>
- ParmVarDecl *NewParam = NewProtoLoc->getArg(NewIdx++);<br>
+ ParmVarDecl *NewParam = NewProtoLoc.getArg(NewIdx++);<br>
Params.push_back(NewParam);<br>
Scope->InstantiatedLocalPackArg(OldParam, NewParam);<br>
}<br>
@@ -2373,10 +2372,10 @@ TemplateDeclInstantiator::SubstFunctionT<br>
// substitution occurred. However, we still need to instantiate<br>
// the function parameters themselves.<br>
TypeLoc OldTL = OldTInfo->getTypeLoc().IgnoreParens();<br>
- if (FunctionProtoTypeLoc *OldProtoLoc<br>
- = dyn_cast<FunctionProtoTypeLoc>(&OldTL)) {<br>
- for (unsigned i = 0, i_end = OldProtoLoc->getNumArgs(); i != i_end; ++i) {<br>
- ParmVarDecl *Parm = VisitParmVarDecl(OldProtoLoc->getArg(i));<br>
+ if (FunctionProtoTypeLoc OldProtoLoc =<br>
+ OldTL.getAs<FunctionProtoTypeLoc>()) {<br>
+ for (unsigned i = 0, i_end = OldProtoLoc.getNumArgs(); i != i_end; ++i) {<br>
+ ParmVarDecl *Parm = VisitParmVarDecl(OldProtoLoc.getArg(i));<br>
if (!Parm)<br>
return 0;<br>
Params.push_back(Parm);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Mon Feb 18 16:06:02 2013<br>
@@ -462,7 +462,8 @@ TypeSourceInfo *Sema::CheckPackExpansion<br>
return 0;<br>
<br>
TypeSourceInfo *TSResult = Context.CreateTypeSourceInfo(Result);<br>
- PackExpansionTypeLoc TL = cast<PackExpansionTypeLoc>(TSResult->getTypeLoc());<br>
+ PackExpansionTypeLoc TL =<br>
+ TSResult->getTypeLoc().castAs<PackExpansionTypeLoc>();<br>
TL.setEllipsisLoc(EllipsisLoc);<br>
<br>
// Copy over the source-location information from the type.<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Feb 18 16:06:02 2013<br>
@@ -3208,13 +3208,13 @@ namespace {<br>
<br>
TypeLoc OldTL = TInfo->getTypeLoc();<br>
if (TInfo->getType()->getAs<ElaboratedType>()) {<br>
- ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(OldTL);<br>
- TemplateSpecializationTypeLoc NamedTL =<br>
- cast<TemplateSpecializationTypeLoc>(ElabTL.getNamedTypeLoc());<br>
+ ElaboratedTypeLoc ElabTL = OldTL.castAs<ElaboratedTypeLoc>();<br>
+ TemplateSpecializationTypeLoc NamedTL = ElabTL.getNamedTypeLoc()<br>
+ .castAs<TemplateSpecializationTypeLoc>();<br>
TL.copy(NamedTL);<br>
}<br>
else<br>
- TL.copy(cast<TemplateSpecializationTypeLoc>(OldTL));<br>
+ TL.copy(OldTL.castAs<TemplateSpecializationTypeLoc>());<br>
}<br>
void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {<br>
assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr);<br>
@@ -3262,7 +3262,7 @@ namespace {<br>
TypeSourceInfo *TInfo = 0;<br>
Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);<br>
if (TInfo) {<br>
- TL.copy(cast<ElaboratedTypeLoc>(TInfo->getTypeLoc()));<br>
+ TL.copy(TInfo->getTypeLoc().castAs<ElaboratedTypeLoc>());<br>
return;<br>
}<br>
}<br>
@@ -3278,7 +3278,7 @@ namespace {<br>
TypeSourceInfo *TInfo = 0;<br>
Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);<br>
assert(TInfo);<br>
- TL.copy(cast<DependentNameTypeLoc>(TInfo->getTypeLoc()));<br>
+ TL.copy(TInfo->getTypeLoc().castAs<DependentNameTypeLoc>());<br>
}<br>
void VisitDependentTemplateSpecializationTypeLoc(<br>
DependentTemplateSpecializationTypeLoc TL) {<br>
@@ -3286,8 +3286,8 @@ namespace {<br>
TypeSourceInfo *TInfo = 0;<br>
Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);<br>
assert(TInfo);<br>
- TL.copy(cast<DependentTemplateSpecializationTypeLoc>(<br>
- TInfo->getTypeLoc()));<br>
+ TL.copy(<br>
+ TInfo->getTypeLoc().castAs<DependentTemplateSpecializationTypeLoc>());<br>
}<br>
void VisitTagTypeLoc(TagTypeLoc TL) {<br>
TL.setNameLoc(DS.getTypeSpecTypeNameLoc());<br>
@@ -3348,7 +3348,7 @@ namespace {<br>
case NestedNameSpecifier::Identifier:<br>
assert(isa<DependentNameType>(ClsTy) && "Unexpected TypeLoc");<br>
{<br>
- DependentNameTypeLoc DNTLoc = cast<DependentNameTypeLoc>(ClsTL);<br>
+ DependentNameTypeLoc DNTLoc = ClsTL.castAs<DependentNameTypeLoc>();<br>
DNTLoc.setElaboratedKeywordLoc(SourceLocation());<br>
DNTLoc.setQualifierLoc(NNSLoc.getPrefix());<br>
DNTLoc.setNameLoc(NNSLoc.getLocalBeginLoc());<br>
@@ -3358,7 +3358,7 @@ namespace {<br>
case NestedNameSpecifier::TypeSpec:<br>
case NestedNameSpecifier::TypeSpecWithTemplate:<br>
if (isa<ElaboratedType>(ClsTy)) {<br>
- ElaboratedTypeLoc ETLoc = *cast<ElaboratedTypeLoc>(&ClsTL);<br>
+ ElaboratedTypeLoc ETLoc = ClsTL.castAs<ElaboratedTypeLoc>();<br>
ETLoc.setElaboratedKeywordLoc(SourceLocation());<br>
ETLoc.setQualifierLoc(NNSLoc.getPrefix());<br>
TypeLoc NamedTL = ETLoc.getNamedTypeLoc();<br>
@@ -3437,13 +3437,12 @@ Sema::GetTypeSourceInfoForDeclarator(Dec<br>
<br>
// Handle parameter packs whose type is a pack expansion.<br>
if (isa<PackExpansionType>(T)) {<br>
- cast<PackExpansionTypeLoc>(CurrTL).setEllipsisLoc(D.getEllipsisLoc());<br>
+ CurrTL.castAs<PackExpansionTypeLoc>().setEllipsisLoc(D.getEllipsisLoc());<br>
CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();<br>
}<br>
<br>
for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {<br>
- while (isa<AttributedTypeLoc>(CurrTL)) {<br>
- AttributedTypeLoc TL = cast<AttributedTypeLoc>(CurrTL);<br>
+ while (AttributedTypeLoc TL = CurrTL.getAs<AttributedTypeLoc>()) {<br>
fillAttributedTypeLoc(TL, D.getTypeObject(i).getAttrs());<br>
CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();<br>
}<br>
<br>
Modified: cfe/trunk/lib/Sema/TreeTransform.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/TreeTransform.h (original)<br>
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Feb 18 16:06:02 2013<br>
@@ -2817,8 +2817,8 @@ TreeTransform<Derived>::TransformNestedN<br>
}<br>
// If the nested-name-specifier is an invalid type def, don't emit an<br>
// error because a previous error should have already been emitted.<br>
- TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);<br>
- if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {<br>
+ TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();<br>
+ if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {<br>
SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)<br>
<< TL.getType() << SS.getRange();<br>
}<br>
@@ -3326,9 +3326,10 @@ QualType<br>
TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {<br>
switch (T.getTypeLocClass()) {<br>
#define ABSTRACT_TYPELOC(CLASS, PARENT)<br>
-#define TYPELOC(CLASS, PARENT) \<br>
- case TypeLoc::CLASS: \<br>
- return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));<br>
+#define TYPELOC(CLASS, PARENT) \<br>
+ case TypeLoc::CLASS: \<br>
+ return getDerived().Transform##CLASS##Type(TLB, \<br>
+ T.castAs<CLASS##TypeLoc>());<br>
#include "clang/AST/TypeLocNodes.def"<br>
}<br>
<br>
@@ -3421,8 +3422,8 @@ TreeTransform<Derived>::TransformTypeInO<br>
QualType Result;<br>
<br>
if (isa<TemplateSpecializationType>(T)) {<br>
- TemplateSpecializationTypeLoc SpecTL<br>
- = cast<TemplateSpecializationTypeLoc>(TL);<br>
+ TemplateSpecializationTypeLoc SpecTL =<br>
+ TL.castAs<TemplateSpecializationTypeLoc>();<br>
<br>
TemplateName Template =<br>
getDerived().TransformTemplateName(SS,<br>
@@ -3435,8 +3436,8 @@ TreeTransform<Derived>::TransformTypeInO<br>
Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,<br>
Template);<br>
} else if (isa<DependentTemplateSpecializationType>(T)) {<br>
- DependentTemplateSpecializationTypeLoc SpecTL<br>
- = cast<DependentTemplateSpecializationTypeLoc>(TL);<br>
+ DependentTemplateSpecializationTypeLoc SpecTL =<br>
+ TL.castAs<DependentTemplateSpecializationTypeLoc>();<br>
<br>
TemplateName Template<br>
= getDerived().RebuildTemplateName(SS,<br>
@@ -3478,8 +3479,8 @@ TreeTransform<Derived>::TransformTypeInO<br>
<br>
TypeLoc TL = TSInfo->getTypeLoc();<br>
if (isa<TemplateSpecializationType>(T)) {<br>
- TemplateSpecializationTypeLoc SpecTL<br>
- = cast<TemplateSpecializationTypeLoc>(TL);<br>
+ TemplateSpecializationTypeLoc SpecTL =<br>
+ TL.castAs<TemplateSpecializationTypeLoc>();<br>
<br>
TemplateName Template<br>
= getDerived().TransformTemplateName(SS,<br>
@@ -3492,8 +3493,8 @@ TreeTransform<Derived>::TransformTypeInO<br>
Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,<br>
Template);<br>
} else if (isa<DependentTemplateSpecializationType>(T)) {<br>
- DependentTemplateSpecializationTypeLoc SpecTL<br>
- = cast<DependentTemplateSpecializationTypeLoc>(TL);<br>
+ DependentTemplateSpecializationTypeLoc SpecTL =<br>
+ TL.castAs<DependentTemplateSpecializationTypeLoc>();<br>
<br>
TemplateName Template<br>
= getDerived().RebuildTemplateName(SS,<br>
@@ -3959,7 +3960,7 @@ TreeTransform<Derived>::TransformFunctio<br>
// If we're substituting into a pack expansion type and we know the<br>
// length we want to expand to, just substitute for the pattern.<br>
TypeLoc OldTL = OldDI->getTypeLoc();<br>
- PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);<br>
+ PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();<br>
<br>
TypeLocBuilder TLB;<br>
TypeLoc NewTL = OldDI->getTypeLoc();<br>
@@ -4025,7 +4026,7 @@ bool TreeTransform<Derived>::<br>
<br>
// Find the parameter packs that could be expanded.<br>
TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();<br>
- PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);<br>
+ PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();<br>
TypeLoc Pattern = ExpansionTL.getPatternLoc();<br>
SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);<br>
assert(Unexpanded.size() > 0 && "Could not find parameter packs!");<br>
@@ -7608,7 +7609,7 @@ TreeTransform<Derived>::TransformTypeTra<br>
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {<br>
TypeSourceInfo *From = E->getArg(I);<br>
TypeLoc FromTL = From->getTypeLoc();<br>
- if (!isa<PackExpansionTypeLoc>(FromTL)) {<br>
+ if (!FromTL.getAs<PackExpansionTypeLoc>()) {<br>
TypeLocBuilder TLB;<br>
TLB.reserve(FromTL.getFullDataSize());<br>
QualType To = getDerived().TransformType(TLB, FromTL);<br>
@@ -7627,7 +7628,7 @@ TreeTransform<Derived>::TransformTypeTra<br>
ArgChanged = true;<br>
<br>
// We have a pack expansion. Instantiate it.<br>
- PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);<br>
+ PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();<br>
TypeLoc PatternTL = ExpansionTL.getPatternLoc();<br>
SmallVector<UnexpandedParameterPack, 2> Unexpanded;<br>
SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);<br>
<br>
Modified: cfe/trunk/lib/Sema/TypeLocBuilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TypeLocBuilder.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TypeLocBuilder.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/TypeLocBuilder.h (original)<br>
+++ cfe/trunk/lib/Sema/TypeLocBuilder.h Mon Feb 18 16:06:02 2013<br>
@@ -75,7 +75,7 @@ class TypeLocBuilder {<br>
/// previously retrieved from this builder.<br>
TypeSpecTypeLoc pushTypeSpec(QualType T) {<br>
size_t LocalSize = TypeSpecTypeLoc::LocalDataSize;<br>
- return cast<TypeSpecTypeLoc>(pushImpl(T, LocalSize));<br>
+ return pushImpl(T, LocalSize).castAs<TypeSpecTypeLoc>();<br>
}<br>
<br>
/// Resets this builder to the newly-initialized state.<br>
@@ -97,8 +97,8 @@ class TypeLocBuilder {<br>
/// Pushes space for a new TypeLoc of the given type. Invalidates<br>
/// any TypeLocs previously retrieved from this builder.<br>
template <class TyLocType> TyLocType push(QualType T) {<br>
- size_t LocalSize = cast<TyLocType>(TypeLoc(T, 0)).getLocalDataSize();<br>
- return cast<TyLocType>(pushImpl(T, LocalSize));<br>
+ size_t LocalSize = TypeLoc(T, 0).castAs<TyLocType>().getLocalDataSize();<br>
+ return pushImpl(T, LocalSize).castAs<TyLocType>();<br>
}<br>
<br>
/// Creates a TypeSourceInfo for the given type.<br>
<br>
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Feb 18 16:06:02 2013<br>
@@ -671,10 +671,10 @@ bool CursorVisitor::VisitClassTemplateSp<br>
// Visit the template arguments used in the specialization.<br>
if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) {<br>
TypeLoc TL = SpecType->getTypeLoc();<br>
- if (TemplateSpecializationTypeLoc *TSTLoc<br>
- = dyn_cast<TemplateSpecializationTypeLoc>(&TL)) {<br>
- for (unsigned I = 0, N = TSTLoc->getNumArgs(); I != N; ++I)<br>
- if (VisitTemplateArgumentLoc(TSTLoc->getArgLoc(I)))<br>
+ if (TemplateSpecializationTypeLoc TSTLoc =<br>
+ TL.getAs<TemplateSpecializationTypeLoc>()) {<br>
+ for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I)<br>
+ if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I)))<br>
return true;<br>
}<br>
}<br>
@@ -750,12 +750,12 @@ bool CursorVisitor::VisitFunctionDecl(Fu<br>
// Visit the function declaration's syntactic components in the order<br>
// written. This requires a bit of work.<br>
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();<br>
- FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL);<br>
+ FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();<br>
<br>
// If we have a function declared directly (without the use of a typedef),<br>
// visit just the return type. Otherwise, just visit the function's type<br>
// now.<br>
- if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL->getResultLoc())) ||<br>
+ if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL.getResultLoc())) ||<br>
(!FTL && Visit(TL)))<br>
return true;<br>
<br>
@@ -771,7 +771,7 @@ bool CursorVisitor::VisitFunctionDecl(Fu<br>
// FIXME: Visit explicitly-specified template arguments!<br>
<br>
// Visit the function parameters, if we have a function type.<br>
- if (FTL && VisitFunctionTypeLoc(*FTL, true))<br>
+ if (FTL && VisitFunctionTypeLoc(FTL, true))<br>
return true;<br>
<br>
// FIXME: Attributes?<br>
@@ -2360,8 +2360,8 @@ bool CursorVisitor::RunVisitorWorkList(V<br>
// Visit the whole type.<br>
if (Visit(TL))<br>
return true;<br>
- } else if (isa<FunctionProtoTypeLoc>(TL)) {<br>
- FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);<br>
+ } else if (FunctionProtoTypeLoc Proto =<br>
+ TL.getAs<FunctionProtoTypeLoc>()) {<br>
if (E->hasExplicitParameters()) {<br>
// Visit parameters.<br>
for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I)<br>
<br>
Modified: cfe/trunk/tools/libclang/CXCursor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CXCursor.cpp Mon Feb 18 16:06:02 2013<br>
@@ -890,7 +890,7 @@ CXCursor cxcursor::getTypeRefCursor(CXCu<br>
<br>
if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {<br>
Ty = ElabT->getNamedType();<br>
- ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(TL);<br>
+ ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();<br>
Loc = ElabTL.getNamedTypeLoc().getBeginLoc();<br>
}<br>
<br>
<br>
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)<br>
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Mon Feb 18 16:06:02 2013<br>
@@ -165,16 +165,16 @@ SourceLocation IndexingContext::CXXBases<br>
if (TL.isNull())<br>
return Loc;<br>
<br>
- if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL))<br>
- TL = QL->getUnqualifiedLoc();<br>
+ if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>())<br>
+ TL = QL.getUnqualifiedLoc();<br>
<br>
- if (const ElaboratedTypeLoc *EL = dyn_cast<ElaboratedTypeLoc>(&TL))<br>
- return EL->getNamedTypeLoc().getBeginLoc();<br>
- if (const DependentNameTypeLoc *DL = dyn_cast<DependentNameTypeLoc>(&TL))<br>
- return DL->getNameLoc();<br>
- if (const DependentTemplateSpecializationTypeLoc *<br>
- DTL = dyn_cast<DependentTemplateSpecializationTypeLoc>(&TL))<br>
- return DTL->getTemplateNameLoc();<br>
+ if (ElaboratedTypeLoc EL = TL.getAs<ElaboratedTypeLoc>())<br>
+ return EL.getNamedTypeLoc().getBeginLoc();<br>
+ if (DependentNameTypeLoc DL = TL.getAs<DependentNameTypeLoc>())<br>
+ return DL.getNameLoc();<br>
+ if (DependentTemplateSpecializationTypeLoc DTL =<br>
+ TL.getAs<DependentTemplateSpecializationTypeLoc>())<br>
+ return DTL.getTemplateNameLoc();<br>
<br>
return Loc;<br>
}<br>
<br>
Modified: cfe/trunk/tools/libclang/RecursiveASTVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=175462&r1=175461&r2=175462&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=175462&r1=175461&r2=175462&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/RecursiveASTVisitor.h (original)<br>
+++ cfe/trunk/tools/libclang/RecursiveASTVisitor.h Mon Feb 18 16:06:02 2013<br>
@@ -535,7 +535,7 @@ bool RecursiveASTVisitor<Derived>::Trave<br>
#define ABSTRACT_TYPELOC(CLASS, BASE)<br>
#define TYPELOC(CLASS, BASE) \<br>
case TypeLoc::CLASS: \<br>
- return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL));<br>
+ return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());<br>
#include "clang/AST/TypeLocNodes.def"<br>
}<br>
<br>
@@ -2027,8 +2027,7 @@ bool RecursiveASTVisitor<Derived>::Trave<br>
if (S->hasExplicitParameters() && S->hasExplicitResultType()) {<br>
// Visit the whole type.<br>
TRY_TO(TraverseTypeLoc(TL));<br>
- } else if (isa<FunctionProtoTypeLoc>(TL)) {<br>
- FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);<br>
+ } else if (FunctionProtoTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) {<br>
if (S->hasExplicitParameters()) {<br>
// Visit parameters.<br>
for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I) {<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>