Introduce a new OpaquePtr<N> struct type, which is a simple POD wrapper for a
pointer. Its purpose in life is to be a glorified void*, but which does not
implicitly convert to void* or other OpaquePtr's with a different UID.
Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>. Change the
entire parser/sema interface to use DeclPtrTy instead of DeclTy*. This
makes the C++ compiler enforce that these aren't convertible to other opaque
types.
We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc,
but I don't plan to do that in the short term.
The one outstanding known problem with this patch is that we lose the
bitmangling optimization where ActionResult<DeclPtrTy> doesn't know how to
bitmangle the success bit into the low bit of DeclPtrTy. I will rectify
this with a subsequent patch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67952 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index 10eec7a..c31435b 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -112,7 +112,7 @@
((DeclContext *)S->getEntity())->isTransparentContext())
S = S->getParent();
- if (S->isDeclScope(D))
+ if (S->isDeclScope(Action::DeclPtrTy::make(D)))
return true;
if (LangOpt.CPlusPlus) {
// C++ 3.3.2p3:
@@ -129,7 +129,7 @@
//
assert(S->getParent() && "No TUScope?");
if (S->getParent()->getFlags() & Scope::ControlScope)
- return S->getParent()->isDeclScope(D);
+ return S->getParent()->isDeclScope(Action::DeclPtrTy::make(D));
}
return false;
}
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index fdc57b6..59a04da 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -44,14 +44,14 @@
Consumer->Initialize(Ctx);
- Parser::DeclTy *ADecl;
+ Parser::DeclPtrTy ADecl;
while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file.
// If we got a null return and something *was* parsed, ignore it. This
// is due to a top-level semicolon, an action override, or a parse error
// skipping something.
if (ADecl) {
- Decl* D = static_cast<Decl*>(ADecl);
+ Decl *D = ADecl.getAs<Decl>();
Consumer->HandleTopLevelDecl(D);
}
};
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 9662c43..7e72a84 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -231,10 +231,10 @@
// Note: we traverse the scope's list of declarations rather than
// the DeclContext's list, because we only want to see the most
// recent declaration of each identifier.
- for (Scope::decl_iterator I = TUScope->decl_begin(),
- IEnd = TUScope->decl_end();
+ for (Scope::decl_iterator I = TUScope->decl_begin(),
+ IEnd = TUScope->decl_end();
I != IEnd; ++I) {
- Decl *D = static_cast<Decl *>(*I);
+ Decl *D = (*I).getAs<Decl>();
if (D->isInvalidDecl())
continue;
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index ab84559..a7c48c8 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -307,7 +307,7 @@
QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
DeclarationName GetNameForDeclarator(Declarator &D);
- QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
+ QualType ObjCGetTypeForMethodDefinition(DeclPtrTy D);
bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
@@ -326,15 +326,16 @@
/// getDeclName - Return a pretty name for the specified decl if possible, or
/// an empty string if not. This is used for pretty crash reporting.
- virtual std::string getDeclName(DeclTy *D);
+ virtual std::string getDeclName(DeclPtrTy D);
virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Scope *S, const CXXScopeSpec *SS);
- virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
+ virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D,
+ DeclPtrTy LastInGroup){
return ActOnDeclarator(S, D, LastInGroup, false);
}
- DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
- bool IsFunctionDefinition);
+ DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy LastInGroup,
+ bool IsFunctionDefinition);
void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
Scope *S);
NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
@@ -355,26 +356,26 @@
bool CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl,
bool &Redeclaration,
bool &OverloadableAttrRequired);
- virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
- virtual void ActOnParamDefaultArgument(DeclTy *param,
+ virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D);
+ virtual void ActOnParamDefaultArgument(DeclPtrTy param,
SourceLocation EqualLoc,
ExprArg defarg);
- virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
+ virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param,
SourceLocation EqualLoc);
- virtual void ActOnParamDefaultArgumentError(DeclTy *param);
- virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
- void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
- void ActOnUninitializedDecl(DeclTy *dcl);
- virtual void SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc);
- virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
+ virtual void ActOnParamDefaultArgumentError(DeclPtrTy param);
+ virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);
+ void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);
+ void ActOnUninitializedDecl(DeclPtrTy dcl);
+ virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);
+ virtual DeclPtrTy FinalizeDeclaratorGroup(Scope *S, DeclPtrTy Group);
virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
- virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
- virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
- virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
+ virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, Declarator &D);
+ virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, DeclPtrTy D);
+ virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D);
- virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
- virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
+ virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body);
+ virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
/// Scope actions.
virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
@@ -382,23 +383,24 @@
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
- virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
+ virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
RecordDecl *AnonRecord);
- virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
- RecordDecl *Record);
+ virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
+ RecordDecl *Record);
- virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
- SourceLocation KWLoc, const CXXScopeSpec &SS,
- IdentifierInfo *Name, SourceLocation NameLoc,
- AttributeList *Attr, AccessSpecifier AS);
+ virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
+ SourceLocation KWLoc, const CXXScopeSpec &SS,
+ IdentifierInfo *Name, SourceLocation NameLoc,
+ AttributeList *Attr, AccessSpecifier AS);
- virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
+ virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart,
IdentifierInfo *ClassName,
- llvm::SmallVectorImpl<DeclTy*> &Decls);
- virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
- Declarator &D, ExprTy *BitfieldWidth);
+ llvm::SmallVectorImpl<DeclPtrTy> &Decls);
+ virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD,
+ SourceLocation DeclStart,
+ Declarator &D, ExprTy *BitfieldWidth);
FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
Declarator &D, Expr *BitfieldWidth,
@@ -410,25 +412,25 @@
AccessSpecifier AS, NamedDecl *PrevDecl,
Declarator *D = 0);
- virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
- Declarator &D, ExprTy *BitfieldWidth,
- tok::ObjCKeywordKind visibility);
+ virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
+ Declarator &D, ExprTy *BitfieldWidth,
+ tok::ObjCKeywordKind visibility);
// This is used for both record definitions and ObjC interface declarations.
virtual void ActOnFields(Scope* S,
- SourceLocation RecLoc, DeclTy *TagDecl,
- DeclTy **Fields, unsigned NumFields,
+ SourceLocation RecLoc, DeclPtrTy TagDecl,
+ DeclPtrTy *Fields, unsigned NumFields,
SourceLocation LBrac, SourceLocation RBrac,
AttributeList *AttrList);
/// ActOnTagStartDefinition - Invoked when we have entered the
/// scope of a tag's definition (e.g., for an enumeration, class,
/// struct, or union).
- virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
+ virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl);
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
/// the definition of a tag (enumeration, class, struct, or union).
- virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
+ virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl);
EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
EnumConstantDecl *LastEnumConst,
@@ -436,12 +438,12 @@
IdentifierInfo *Id,
ExprArg val);
- virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
- DeclTy *LastEnumConstant,
- SourceLocation IdLoc, IdentifierInfo *Id,
- SourceLocation EqualLoc, ExprTy *Val);
- virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
- DeclTy **Elements, unsigned NumElements);
+ virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl,
+ DeclPtrTy LastEnumConstant,
+ SourceLocation IdLoc, IdentifierInfo *Id,
+ SourceLocation EqualLoc, ExprTy *Val);
+ virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDecl,
+ DeclPtrTy *Elements, unsigned NumElements);
DeclContext *getContainingDC(DeclContext *DC);
@@ -1082,7 +1084,8 @@
virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
MultiStmtArg Elts,
bool isStmtExpr);
- virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
+ virtual OwningStmtResult ActOnDeclStmt(DeclPtrTy Decl,
+ SourceLocation StartLoc,
SourceLocation EndLoc);
virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
SourceLocation DotDotDotLoc, ExprArg RHSVal,
@@ -1147,7 +1150,7 @@
virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
SourceLocation RParen,
- DeclTy *Parm, StmtArg Body,
+ DeclPtrTy Parm, StmtArg Body,
StmtArg CatchList);
virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
@@ -1164,9 +1167,9 @@
ExprArg SynchExpr,
StmtArg SynchBody);
- virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
+ virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D);
virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
- DeclTy *ExDecl,
+ DeclPtrTy ExDecl,
StmtArg HandlerBlock);
virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
StmtArg TryBlock,
@@ -1255,7 +1258,7 @@
tok::TokenKind OpKind,
SourceLocation MemberLoc,
IdentifierInfo &Member,
- DeclTy *ImplDecl=0);
+ DeclPtrTy ImplDecl);
bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
FunctionDecl *FDecl,
const FunctionProtoType *Proto,
@@ -1358,32 +1361,32 @@
//===---------------------------- C++ Features --------------------------===//
// Act on C++ namespaces
- virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
- IdentifierInfo *Ident,
- SourceLocation LBrace);
- virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
+ virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
+ IdentifierInfo *Ident,
+ SourceLocation LBrace);
+ virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace);
- virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
- SourceLocation UsingLoc,
- SourceLocation NamespcLoc,
- const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *NamespcName,
- AttributeList *AttrList);
+ virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope,
+ SourceLocation UsingLoc,
+ SourceLocation NamespcLoc,
+ const CXXScopeSpec &SS,
+ SourceLocation IdentLoc,
+ IdentifierInfo *NamespcName,
+ AttributeList *AttrList);
void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
- virtual DeclTy *ActOnNamespaceAliasDef(Scope *CurScope,
- SourceLocation AliasLoc,
- IdentifierInfo *Alias,
- const CXXScopeSpec &SS,
- SourceLocation NamespaceLoc,
- IdentifierInfo *NamespaceName);
+ virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope,
+ SourceLocation AliasLoc,
+ IdentifierInfo *Alias,
+ const CXXScopeSpec &SS,
+ SourceLocation NamespaceLoc,
+ IdentifierInfo *NamespaceName);
/// AddCXXDirectInitializerToDecl - This action is called immediately after
/// ActOnDeclarator, when a C++ direct initializer is present.
/// e.g: "int x(1);"
- virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
+ virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
@@ -1565,15 +1568,15 @@
//===--------------------------------------------------------------------===//
// C++ Declarations
//
- virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
- SourceLocation ExternLoc,
- SourceLocation LangLoc,
- const char *Lang,
- unsigned StrSize,
- SourceLocation LBraceLoc);
- virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
- DeclTy *LinkageSpec,
- SourceLocation RBraceLoc);
+ virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S,
+ SourceLocation ExternLoc,
+ SourceLocation LangLoc,
+ const char *Lang,
+ unsigned StrSize,
+ SourceLocation LBraceLoc);
+ virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S,
+ DeclPtrTy LinkageSpec,
+ SourceLocation RBraceLoc);
//===--------------------------------------------------------------------===//
@@ -1582,11 +1585,13 @@
virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
const CXXScopeSpec *SS);
- virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
- Declarator &D, ExprTy *BitfieldWidth,
- ExprTy *Init, DeclTy *LastInGroup);
+ virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
+ Declarator &D,
+ ExprTy *BitfieldWidth,
+ ExprTy *Init,
+ DeclPtrTy LastInGroup);
- virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
+ virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorD,
Scope *S,
IdentifierInfo *MemberOrBase,
SourceLocation IdLoc,
@@ -1597,22 +1602,24 @@
void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
- virtual void ActOnMemInitializers(DeclTy *ConstructorDecl,
+ virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl,
SourceLocation ColonLoc,
MemInitTy **MemInits, unsigned NumMemInits);
virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
- DeclTy *TagDecl,
+ DeclPtrTy TagDecl,
SourceLocation LBrac,
SourceLocation RBrac);
- virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
- virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
- virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
+ virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S,
+ DeclPtrTy Method);
+ virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param);
+ virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S,
+ DeclPtrTy Method);
- virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
- ExprArg AssertExpr,
- ExprArg AssertMessageExpr);
+ virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
+ ExprArg AssertExpr,
+ ExprArg AssertMessageExpr);
bool CheckConstructorDeclarator(Declarator &D, QualType &R,
FunctionDecl::StorageClass& SC);
@@ -1621,7 +1628,7 @@
FunctionDecl::StorageClass& SC);
bool CheckConversionDeclarator(Declarator &D, QualType &R,
FunctionDecl::StorageClass& SC);
- DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
+ DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion);
//===--------------------------------------------------------------------===//
// C++ Derived Classes
@@ -1633,7 +1640,7 @@
bool Virtual, AccessSpecifier Access,
QualType BaseType,
SourceLocation BaseLoc);
- virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
+ virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl,
SourceRange SpecifierRange,
bool Virtual, AccessSpecifier Access,
TypeTy *basetype, SourceLocation
@@ -1641,7 +1648,7 @@
bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
unsigned NumBases);
- virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
+ virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases,
unsigned NumBases);
bool IsDerivedFrom(QualType Derived, QualType Base);
@@ -1686,36 +1693,36 @@
// C++ Templates [C++ 14]
//
virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
- DeclTy *&TemplateDecl,
+ DeclPtrTy &TemplateDecl,
const CXXScopeSpec *SS = 0);
bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
- TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
+ TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl);
- virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
- SourceLocation KeyLoc,
- IdentifierInfo *ParamName,
- SourceLocation ParamNameLoc,
- unsigned Depth, unsigned Position);
- virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
+ virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename,
+ SourceLocation KeyLoc,
+ IdentifierInfo *ParamName,
+ SourceLocation ParamNameLoc,
+ unsigned Depth, unsigned Position);
+ virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam,
SourceLocation EqualLoc,
SourceLocation DefaultLoc,
TypeTy *Default);
QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
- virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
- unsigned Depth,
- unsigned Position);
- virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
+ virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
+ unsigned Depth,
+ unsigned Position);
+ virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam,
SourceLocation EqualLoc,
ExprArg Default);
- virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
- SourceLocation TmpLoc,
- TemplateParamsTy *Params,
- IdentifierInfo *ParamName,
- SourceLocation ParamNameLoc,
- unsigned Depth,
- unsigned Position);
- virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
+ virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S,
+ SourceLocation TmpLoc,
+ TemplateParamsTy *Params,
+ IdentifierInfo *ParamName,
+ SourceLocation ParamNameLoc,
+ unsigned Depth,
+ unsigned Position);
+ virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam,
SourceLocation EqualLoc,
ExprArg Default);
@@ -1724,7 +1731,7 @@
SourceLocation ExportLoc,
SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
- DeclTy **Params, unsigned NumParams,
+ DeclPtrTy *Params, unsigned NumParams,
SourceLocation RAngleLoc);
bool CheckTemplateParameterList(TemplateParameterList *NewParams,
TemplateParameterList *OldParams);
@@ -1745,7 +1752,7 @@
SourceLocation RAngleLoc);
virtual TypeResult
- ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
+ ActOnClassTemplateId(DeclPtrTy Template, SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgs,
SourceLocation *TemplateArgLocs,
@@ -1761,7 +1768,7 @@
ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
SourceLocation KWLoc,
const CXXScopeSpec &SS,
- DeclTy *Template,
+ DeclPtrTy Template,
SourceLocation TemplateNameLoc,
SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgs,
@@ -1981,17 +1988,17 @@
}
// Objective-C declarations.
- virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
- IdentifierInfo *ClassName,
- SourceLocation ClassLoc,
- IdentifierInfo *SuperName,
- SourceLocation SuperLoc,
- DeclTy * const *ProtoRefs,
- unsigned NumProtoRefs,
- SourceLocation EndProtoLoc,
- AttributeList *AttrList);
+ virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
+ IdentifierInfo *ClassName,
+ SourceLocation ClassLoc,
+ IdentifierInfo *SuperName,
+ SourceLocation SuperLoc,
+ const DeclPtrTy *ProtoRefs,
+ unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc,
+ AttributeList *AttrList);
- virtual DeclTy *ActOnCompatiblityAlias(
+ virtual DeclPtrTy ActOnCompatiblityAlias(
SourceLocation AtCompatibilityAliasLoc,
IdentifierInfo *AliasName, SourceLocation AliasLocation,
IdentifierInfo *ClassName, SourceLocation ClassLocation);
@@ -2001,40 +2008,40 @@
SourceLocation &PLoc, SourceLocation PrevLoc,
const ObjCList<ObjCProtocolDecl> &PList);
- virtual DeclTy *ActOnStartProtocolInterface(
+ virtual DeclPtrTy ActOnStartProtocolInterface(
SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
- DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
+ const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs,
SourceLocation EndProtoLoc,
AttributeList *AttrList);
- virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
- IdentifierInfo *ClassName,
- SourceLocation ClassLoc,
- IdentifierInfo *CategoryName,
- SourceLocation CategoryLoc,
- DeclTy * const *ProtoRefs,
- unsigned NumProtoRefs,
- SourceLocation EndProtoLoc);
+ virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
+ IdentifierInfo *ClassName,
+ SourceLocation ClassLoc,
+ IdentifierInfo *CategoryName,
+ SourceLocation CategoryLoc,
+ const DeclPtrTy *ProtoRefs,
+ unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc);
- virtual DeclTy *ActOnStartClassImplementation(
+ virtual DeclPtrTy ActOnStartClassImplementation(
SourceLocation AtClassImplLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperClassname,
SourceLocation SuperClassLoc);
- virtual DeclTy *ActOnStartCategoryImplementation(
+ virtual DeclPtrTy ActOnStartCategoryImplementation(
SourceLocation AtCatImplLoc,
IdentifierInfo *ClassName,
SourceLocation ClassLoc,
IdentifierInfo *CatName,
SourceLocation CatLoc);
- virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
+ virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
IdentifierInfo **IdentList,
unsigned NumElts);
- virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
+ virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
const IdentifierLocPair *IdentList,
unsigned NumElts,
AttributeList *attrList);
@@ -2042,7 +2049,7 @@
virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
unsigned NumProtocols,
- llvm::SmallVectorImpl<DeclTy *> &Protocols);
+ llvm::SmallVectorImpl<DeclPtrTy> &Protocols);
/// Ensure attributes are consistent with type.
/// \param [in, out] Attributes The attributes to check; they will
@@ -2057,7 +2064,7 @@
void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
void MergeProtocolPropertiesIntoClass(Decl *CDecl,
- DeclTy *MergeProtocols);
+ DeclPtrTy MergeProtocols);
void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
ObjCInterfaceDecl *ID);
@@ -2065,28 +2072,29 @@
void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
ObjCProtocolDecl *PDecl);
- virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
- DeclTy **allMethods = 0, unsigned allNum = 0,
- DeclTy **allProperties = 0, unsigned pNum = 0,
- DeclTy **allTUVars = 0, unsigned tuvNum = 0);
+ virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl,
+ DeclPtrTy *allMethods = 0, unsigned allNum = 0,
+ DeclPtrTy *allProperties = 0, unsigned pNum = 0,
+ DeclPtrTy *allTUVars = 0, unsigned tuvNum = 0);
- virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
- FieldDeclarator &FD, ObjCDeclSpec &ODS,
- Selector GetterSel, Selector SetterSel,
- DeclTy *ClassCategory, bool *OverridingProperty,
- tok::ObjCKeywordKind MethodImplKind);
+ virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc,
+ FieldDeclarator &FD, ObjCDeclSpec &ODS,
+ Selector GetterSel, Selector SetterSel,
+ DeclPtrTy ClassCategory,
+ bool *OverridingProperty,
+ tok::ObjCKeywordKind MethodImplKind);
- virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
- SourceLocation PropertyLoc,
- bool ImplKind, DeclTy *ClassImplDecl,
- IdentifierInfo *PropertyId,
- IdentifierInfo *PropertyIvar);
+ virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc,
+ SourceLocation PropertyLoc,
+ bool ImplKind,DeclPtrTy ClassImplDecl,
+ IdentifierInfo *PropertyId,
+ IdentifierInfo *PropertyIvar);
- virtual DeclTy *ActOnMethodDeclaration(
+ virtual DeclPtrTy ActOnMethodDeclaration(
SourceLocation BeginLoc, // location of the + or -.
SourceLocation EndLoc, // location of the ; or {.
tok::TokenKind MethodType,
- DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
+ DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fa386ef..f98da95 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -32,8 +32,8 @@
/// getDeclName - Return a pretty name for the specified decl if possible, or
/// an empty string if not. This is used for pretty crash reporting.
-std::string Sema::getDeclName(DeclTy *d) {
- Decl *D = static_cast<Decl *>(d);
+std::string Sema::getDeclName(DeclPtrTy d) {
+ Decl *D = d.getAs<Decl>();
if (NamedDecl *DN = dyn_cast_or_null<NamedDecl>(D))
return DN->getQualifiedNameAsString();
return "";
@@ -177,7 +177,7 @@
((DeclContext *)S->getEntity())->isTransparentContext())
S = S->getParent();
- S->AddDecl(D);
+ S->AddDecl(DeclPtrTy::make(D));
// Add scoped declarations into their context, so that they can be
// found later. Declarations without a context won't be inserted
@@ -207,7 +207,7 @@
// This is a redeclaration. Remove it from the chain and
// break out, so that we'll add in the shadowed
// declaration.
- S->RemoveDecl(*I);
+ S->RemoveDecl(DeclPtrTy::make(*I));
if (PrevDecl == *I) {
IdResolver.RemoveDecl(*I);
IdResolver.AddDecl(TD);
@@ -238,10 +238,11 @@
IdResolver.end(),
std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
FD));
- if (Redecl != IdResolver.end() && S->isDeclScope(*Redecl)) {
+ if (Redecl != IdResolver.end() &&
+ S->isDeclScope(DeclPtrTy::make(*Redecl))) {
// There is already a declaration of a function on our
// IdResolver chain. Replace it with this declaration.
- S->RemoveDecl(*Redecl);
+ S->RemoveDecl(DeclPtrTy::make(*Redecl));
IdResolver.RemoveDecl(*Redecl);
}
}
@@ -256,7 +257,7 @@
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
- Decl *TmpD = static_cast<Decl*>(*I);
+ Decl *TmpD = (*I).getAs<Decl>();
assert(TmpD && "This decl didn't get pushed??");
assert(isa<NamedDecl>(TmpD) && "Decl isn't NamedDecl?");
@@ -903,7 +904,7 @@
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
-Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
+Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
TagDecl *Tag = 0;
if (DS.getTypeSpecType() == DeclSpec::TST_class ||
DS.getTypeSpecType() == DeclSpec::TST_struct ||
@@ -926,7 +927,7 @@
// about them.
// FIXME: Should we support Microsoft's extensions in this area?
if (Record->getDeclName() && getLangOptions().Microsoft)
- return Tag;
+ return DeclPtrTy::make(Tag);
}
if (!DS.isMissingDeclaratorOk() &&
@@ -937,15 +938,15 @@
Tag && isa<EnumDecl>(Tag)) {
Diag(DS.getSourceRange().getBegin(), diag::ext_typedef_without_a_name)
<< DS.getSourceRange();
- return Tag;
+ return DeclPtrTy::make(Tag);
}
Diag(DS.getSourceRange().getBegin(), diag::err_no_declarators)
<< DS.getSourceRange();
- return 0;
+ return DeclPtrTy();
}
- return Tag;
+ return DeclPtrTy::make(Tag);
}
/// InjectAnonymousStructOrUnionMembers - Inject the members of the
@@ -992,7 +993,7 @@
// considered to have been defined in the scope in which the
// anonymous union is declared.
Owner->makeDeclVisibleInContext(*F);
- S->AddDecl(*F);
+ S->AddDecl(DeclPtrTy::make(*F));
IdResolver.AddDecl(*F);
}
} else if (const RecordType *InnerRecordType
@@ -1011,8 +1012,8 @@
/// anonymous structure or union. Anonymous unions are a C++ feature
/// (C++ [class.union]) and a GNU C extension; anonymous structures
/// are a GNU C and GNU C++ extension.
-Sema::DeclTy *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
- RecordDecl *Record) {
+Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
+ RecordDecl *Record) {
DeclContext *Owner = Record->getDeclContext();
// Diagnose whether this anonymous struct/union is an extension.
@@ -1165,7 +1166,7 @@
if (Invalid)
Anon->setInvalidDecl();
- return Anon;
+ return DeclPtrTy::make(Anon);
}
@@ -1233,10 +1234,11 @@
return true;
}
-Sema::DeclTy *
-Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
+Sema::DeclPtrTy
+Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy lastDecl,
bool IsFunctionDefinition) {
- NamedDecl *LastDeclarator = dyn_cast_or_null<NamedDecl>((Decl *)lastDecl);
+ NamedDecl *LastDeclarator =
+ dyn_cast_or_null<NamedDecl>(lastDecl.getAs<Decl>());
DeclarationName Name = GetNameForDeclarator(D);
// All of these full declarators require an identifier. If it doesn't have
@@ -1246,7 +1248,7 @@
Diag(D.getDeclSpec().getSourceRange().getBegin(),
diag::err_declarator_need_ident)
<< D.getDeclSpec().getSourceRange() << D.getSourceRange();
- return 0;
+ return DeclPtrTy();
}
// The scope passed in may not be a decl scope. Zip up the scope tree until
@@ -1366,7 +1368,7 @@
}
if (New == 0)
- return 0;
+ return DeclPtrTy();
// If this has an identifier and is not an invalid redeclaration,
// add it to the scope stack.
@@ -1376,7 +1378,7 @@
if (D.getInvalidType() || InvalidDecl)
New->setInvalidDecl();
- return New;
+ return DeclPtrTy::make(New);
}
/// TryToFixInvalidVariablyModifiedType - Helper method to turn variable array
@@ -1442,11 +1444,11 @@
if (S && IdResolver.ReplaceDecl(PrevDecl, ND)) {
// The previous declaration was found on the identifer resolver
// chain, so remove it from its scope.
- while (S && !S->isDeclScope(PrevDecl))
+ while (S && !S->isDeclScope(DeclPtrTy::make(PrevDecl)))
S = S->getParent();
if (S)
- S->RemoveDecl(PrevDecl);
+ S->RemoveDecl(DeclPtrTy::make(PrevDecl));
}
}
@@ -2009,9 +2011,9 @@
// already checks for that case.
if (FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 &&
FTI.ArgInfo[0].Param &&
- ((ParmVarDecl*)FTI.ArgInfo[0].Param)->getType()->isVoidType()) {
+ FTI.ArgInfo[0].Param.getAs<ParmVarDecl>()->getType()->isVoidType()) {
// empty arg list, don't push any params.
- ParmVarDecl *Param = (ParmVarDecl*)FTI.ArgInfo[0].Param;
+ ParmVarDecl *Param = FTI.ArgInfo[0].Param.getAs<ParmVarDecl>();
// In C++, the empty parameter-type-list must be spelled "void"; a
// typedef of void is not permitted.
@@ -2020,10 +2022,8 @@
Diag(Param->getLocation(), diag::ext_param_typedef_of_void);
}
} else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) {
- for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
- ParmVarDecl *PVD = (ParmVarDecl *)FTI.ArgInfo[i].Param;
- Params.push_back(PVD);
- }
+ for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
+ Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
}
NewFD->setParams(Context, &Params[0], Params.size());
@@ -2267,15 +2267,15 @@
return true;
}
-void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init) {
+void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init) {
AddInitializerToDecl(dcl, move(init), /*DirectInit=*/false);
}
/// AddInitializerToDecl - Adds the initializer Init to the
/// declaration dcl. If DirectInit is true, this is C++ direct
/// initialization rather than copy initialization.
-void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) {
- Decl *RealDecl = static_cast<Decl *>(dcl);
+void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
+ Decl *RealDecl = dcl.getAs<Decl>();
// If there is no declaration, there was an error parsing it. Just ignore
// the initializer.
if (RealDecl == 0)
@@ -2430,8 +2430,8 @@
return;
}
-void Sema::ActOnUninitializedDecl(DeclTy *dcl) {
- Decl *RealDecl = static_cast<Decl *>(dcl);
+void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) {
+ Decl *RealDecl = dcl.getAs<Decl>();
// If there is no declaration, there was an error parsing it. Just ignore it.
if (RealDecl == 0)
@@ -2518,11 +2518,11 @@
}
/// The declarators are chained together backwards, reverse the list.
-Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
+Sema::DeclPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, DeclPtrTy group) {
// Often we have single declarators, handle them quickly.
- Decl *Group = static_cast<Decl*>(group);
+ Decl *Group = group.getAs<Decl>();
if (Group == 0)
- return 0;
+ return DeclPtrTy();
Decl *NewGroup = 0;
if (Group->getNextDeclarator() == 0)
@@ -2578,12 +2578,12 @@
}
}
}
- return NewGroup;
+ return DeclPtrTy::make(NewGroup);
}
/// ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator()
/// to introduce parameters into function prototype scope.
-Sema::DeclTy *
+Sema::DeclPtrTy
Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
const DeclSpec &DS = D.getDeclSpec();
@@ -2625,7 +2625,7 @@
DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl);
// Just pretend that we didn't see the previous declaration.
PrevDecl = 0;
- } else if (S->isDeclScope(PrevDecl)) {
+ } else if (S->isDeclScope(DeclPtrTy::make(PrevDecl))) {
Diag(D.getIdentifierLoc(), diag::err_param_redefinition) << II;
// Recover by removing the name
@@ -2675,13 +2675,12 @@
}
// Add the parameter declaration into this scope.
- S->AddDecl(New);
+ S->AddDecl(DeclPtrTy::make(New));
if (II)
IdResolver.AddDecl(New);
ProcessDeclAttributes(New, D);
- return New;
-
+ return DeclPtrTy::make(New);
}
void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D) {
@@ -2710,7 +2709,8 @@
}
}
-Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
+Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
+ Declarator &D) {
assert(getCurFunctionDecl() == 0 && "Function parsing confused");
assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
"Not a function declarator!");
@@ -2723,13 +2723,12 @@
Scope *ParentScope = FnBodyScope->getParent();
return ActOnStartOfFunctionDef(FnBodyScope,
- ActOnDeclarator(ParentScope, D, 0,
- /*IsFunctionDefinition=*/true));
+ ActOnDeclarator(ParentScope, D, DeclPtrTy(),
+ /*IsFunctionDefinition=*/true));
}
-Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
- Decl *decl = static_cast<Decl*>(D);
- FunctionDecl *FD = cast<FunctionDecl>(decl);
+Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
+ FunctionDecl *FD = cast<FunctionDecl>(D.getAs<Decl>());
// See if this is a redefinition.
const FunctionDecl *Definition;
@@ -2778,7 +2777,7 @@
diag::err_attribute_can_be_applied_only_to_symbol_declaration)
<< "dllimport";
FD->setInvalidDecl();
- return FD;
+ return DeclPtrTy::make(FD);
} else {
// If a symbol previously declared dllimport is later defined, the
// attribute is ignored in subsequent references, and a warning is
@@ -2788,7 +2787,7 @@
<< FD->getNameAsCString() << "dllimport";
}
}
- return FD;
+ return DeclPtrTy::make(FD);
}
static bool StatementCreatesScope(Stmt* S) {
@@ -2868,8 +2867,8 @@
}
}
-Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
- Decl *dcl = static_cast<Decl *>(D);
+Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) {
+ Decl *dcl = D.getAs<Decl>();
Stmt *Body = static_cast<Stmt*>(BodyArg.release());
if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(dcl)) {
FD->setBody(cast<CompoundStmt>(Body));
@@ -2879,7 +2878,7 @@
MD->setBody(cast<CompoundStmt>(Body));
} else {
Body->Destroy(Context);
- return 0;
+ return DeclPtrTy();
}
PopDeclContext();
// Verify and clean out per-function state.
@@ -2974,7 +2973,7 @@
CurContext = Context.getTranslationUnitDecl();
FunctionDecl *FD =
- dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(TUScope, D, 0)));
+ dyn_cast<FunctionDecl>(ActOnDeclarator(TUScope, D, DeclPtrTy()).getAs<Decl>());
FD->setImplicit();
CurContext = PrevDC;
@@ -3087,10 +3086,10 @@
/// former case, Name will be non-null. In the later case, Name will be null.
/// TagSpec indicates what kind of tag this is. TK indicates whether this is a
/// reference/declaration/definition of a tag.
-Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
- SourceLocation KWLoc, const CXXScopeSpec &SS,
- IdentifierInfo *Name, SourceLocation NameLoc,
- AttributeList *Attr, AccessSpecifier AS) {
+Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
+ SourceLocation KWLoc, const CXXScopeSpec &SS,
+ IdentifierInfo *Name, SourceLocation NameLoc,
+ AttributeList *Attr, AccessSpecifier AS) {
// If this is not a definition, it must have a name.
assert((Name != 0 || TK == TK_Definition) &&
"Nameless record must be a definition!");
@@ -3197,7 +3196,7 @@
// For our current ASTs this shouldn't be a problem, but will
// need to be changed with DeclGroups.
if (TK == TK_Reference)
- return PrevDecl;
+ return DeclPtrTy::make(PrevDecl);
// Diagnose attempts to redefine a tag.
if (TK == TK_Definition) {
@@ -3398,12 +3397,12 @@
CurContext->addDecl(New);
}
- return New;
+ return DeclPtrTy::make(New);
}
-void Sema::ActOnTagStartDefinition(Scope *S, DeclTy *TagD) {
+void Sema::ActOnTagStartDefinition(Scope *S, DeclPtrTy TagD) {
AdjustDeclIfTemplate(TagD);
- TagDecl *Tag = cast<TagDecl>((Decl *)TagD);
+ TagDecl *Tag = cast<TagDecl>(TagD.getAs<Decl>());
// Enter the tag context.
PushDeclContext(S, Tag);
@@ -3432,9 +3431,9 @@
}
}
-void Sema::ActOnTagFinishDefinition(Scope *S, DeclTy *TagD) {
+void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD) {
AdjustDeclIfTemplate(TagD);
- TagDecl *Tag = cast<TagDecl>((Decl *)TagD);
+ TagDecl *Tag = cast<TagDecl>(TagD.getAs<Decl>());
if (isa<CXXRecordDecl>(Tag))
FieldCollector->FinishClass();
@@ -3488,13 +3487,13 @@
/// ActOnField - Each field of a struct/union/class is passed into this in order
/// to create a FieldDecl object for it.
-Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagD,
- SourceLocation DeclStart,
- Declarator &D, ExprTy *BitfieldWidth) {
-
- return HandleField(S, static_cast<RecordDecl*>(TagD), DeclStart, D,
- static_cast<Expr*>(BitfieldWidth),
- AS_public);
+Sema::DeclPtrTy Sema::ActOnField(Scope *S, DeclPtrTy TagD,
+ SourceLocation DeclStart,
+ Declarator &D, ExprTy *BitfieldWidth) {
+ FieldDecl *Res = HandleField(S, cast_or_null<RecordDecl>(TagD.getAs<Decl>()),
+ DeclStart, D, static_cast<Expr*>(BitfieldWidth),
+ AS_public);
+ return DeclPtrTy::make(Res);
}
/// HandleField - Analyze a field of a C struct or a C++ data member.
@@ -3647,10 +3646,10 @@
/// ActOnIvar - Each ivar field of an objective-c class is passed into this
/// in order to create an IvarDecl object for it.
-Sema::DeclTy *Sema::ActOnIvar(Scope *S,
- SourceLocation DeclStart,
- Declarator &D, ExprTy *BitfieldWidth,
- tok::ObjCKeywordKind Visibility) {
+Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
+ SourceLocation DeclStart,
+ Declarator &D, ExprTy *BitfieldWidth,
+ tok::ObjCKeywordKind Visibility) {
IdentifierInfo *II = D.getIdentifier();
Expr *BitWidth = (Expr*)BitfieldWidth;
@@ -3713,19 +3712,19 @@
if (II) {
// FIXME: When interfaces are DeclContexts, we'll need to add
// these to the interface.
- S->AddDecl(NewID);
+ S->AddDecl(DeclPtrTy::make(NewID));
IdResolver.AddDecl(NewID);
}
- return NewID;
+ return DeclPtrTy::make(NewID);
}
void Sema::ActOnFields(Scope* S,
- SourceLocation RecLoc, DeclTy *RecDecl,
- DeclTy **Fields, unsigned NumFields,
+ SourceLocation RecLoc, DeclPtrTy RecDecl,
+ DeclPtrTy *Fields, unsigned NumFields,
SourceLocation LBrac, SourceLocation RBrac,
AttributeList *Attr) {
- Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
+ Decl *EnclosingDecl = RecDecl.getAs<Decl>();
assert(EnclosingDecl && "missing record or interface decl");
// If the decl this is being inserted into is invalid, then it may be a
@@ -3742,8 +3741,7 @@
RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
for (unsigned i = 0; i != NumFields; ++i) {
- FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
- assert(FD && "missing field decl");
+ FieldDecl *FD = cast<FieldDecl>(Fields[i].getAs<Decl>());
// Get the type for the field.
Type *FDTy = FD->getType().getTypePtr();
@@ -3916,13 +3914,14 @@
}
-Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
- DeclTy *lastEnumConst,
- SourceLocation IdLoc, IdentifierInfo *Id,
- SourceLocation EqualLoc, ExprTy *val) {
- EnumDecl *TheEnumDecl = cast<EnumDecl>(static_cast<Decl*>(theEnumDecl));
+Sema::DeclPtrTy Sema::ActOnEnumConstant(Scope *S, DeclPtrTy theEnumDecl,
+ DeclPtrTy lastEnumConst,
+ SourceLocation IdLoc,
+ IdentifierInfo *Id,
+ SourceLocation EqualLoc, ExprTy *val) {
+ EnumDecl *TheEnumDecl = cast<EnumDecl>(theEnumDecl.getAs<Decl>());
EnumConstantDecl *LastEnumConst =
- cast_or_null<EnumConstantDecl>(static_cast<Decl*>(lastEnumConst));
+ cast_or_null<EnumConstantDecl>(lastEnumConst.getAs<Decl>());
Expr *Val = static_cast<Expr*>(val);
// The scope passed in may not be a decl scope. Zip up the scope tree until
@@ -3951,7 +3950,7 @@
Diag(IdLoc, diag::err_redefinition) << Id;
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
if (Val) Val->Destroy(Context);
- return 0;
+ return DeclPtrTy();
}
}
@@ -3962,14 +3961,14 @@
if (New)
PushOnScopeChains(New, S);
- return New;
+ return DeclPtrTy::make(New);
}
// FIXME: For consistency with ActOnFields(), we should have the parser
// pass in the source location for the left/right braces.
-void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
- DeclTy **Elements, unsigned NumElements) {
- EnumDecl *Enum = cast<EnumDecl>(static_cast<Decl*>(EnumDeclX));
+void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDeclX,
+ DeclPtrTy *Elements, unsigned NumElements) {
+ EnumDecl *Enum = cast<EnumDecl>(EnumDeclX.getAs<Decl>());
QualType EnumType = Context.getTypeDeclType(Enum);
// TODO: If the result value doesn't fit in an int, it must be a long or long
@@ -3987,7 +3986,7 @@
for (unsigned i = 0; i != NumElements; ++i) {
EnumConstantDecl *ECD =
- cast_or_null<EnumConstantDecl>(static_cast<Decl*>(Elements[i]));
+ cast_or_null<EnumConstantDecl>(Elements[i].getAs<Decl>());
if (!ECD) continue; // Already issued a diagnostic.
// If the enum value doesn't fit in an int, emit an extension warning.
@@ -4061,7 +4060,7 @@
// the type of the enum if needed.
for (unsigned i = 0; i != NumElements; ++i) {
EnumConstantDecl *ECD =
- cast_or_null<EnumConstantDecl>(static_cast<Decl*>(Elements[i]));
+ cast_or_null<EnumConstantDecl>(Elements[i].getAs<Decl>());
if (!ECD) continue; // Already issued a diagnostic.
// Standard C says the enumerators have int type, but we allow, as an
@@ -4135,10 +4134,11 @@
Enum->completeDefinition(Context, BestType);
}
-Sema::DeclTy *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc,
- ExprArg expr) {
+Sema::DeclPtrTy Sema::ActOnFileScopeAsmDecl(SourceLocation Loc,
+ ExprArg expr) {
StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr.release());
- return FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString);
+ return DeclPtrTy::make(FileScopeAsmDecl::Create(Context, CurContext,
+ Loc, AsmString));
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 67c8777..27d42dd 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -105,9 +105,9 @@
/// provided for a function parameter is well-formed. If so, attach it
/// to the parameter declaration.
void
-Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc,
+Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc,
ExprArg defarg) {
- ParmVarDecl *Param = (ParmVarDecl *)param;
+ ParmVarDecl *Param = cast<ParmVarDecl>(param.getAs<Decl>());
ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg.release());
QualType ParamType = Param->getType();
@@ -153,17 +153,17 @@
/// argument for a function parameter, but we can't parse it yet
/// because we're inside a class definition. Note that this default
/// argument will be parsed later.
-void Sema::ActOnParamUnparsedDefaultArgument(DeclTy *param,
+void Sema::ActOnParamUnparsedDefaultArgument(DeclPtrTy param,
SourceLocation EqualLoc) {
- ParmVarDecl *Param = (ParmVarDecl*)param;
+ ParmVarDecl *Param = cast<ParmVarDecl>(param.getAs<Decl>());
if (Param)
Param->setUnparsedDefaultArg();
}
/// ActOnParamDefaultArgumentError - Parsing or semantic analysis of
/// the default argument for the parameter param failed.
-void Sema::ActOnParamDefaultArgumentError(DeclTy *param) {
- ((ParmVarDecl*)param)->setInvalidDecl();
+void Sema::ActOnParamDefaultArgumentError(DeclPtrTy param) {
+ cast<ParmVarDecl>(param.getAs<Decl>())->setInvalidDecl();
}
/// CheckExtraCXXDefaultArguments - Check for any extra default
@@ -179,11 +179,12 @@
// parameter pack. If it is specified in a
// parameter-declaration-clause, it shall not occur within a
// declarator or abstract-declarator of a parameter-declaration.
- for (unsigned i = 0; i < D.getNumTypeObjects(); ++i) {
+ for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
DeclaratorChunk &chunk = D.getTypeObject(i);
if (chunk.Kind == DeclaratorChunk::Function) {
- for (unsigned argIdx = 0; argIdx < chunk.Fun.NumArgs; ++argIdx) {
- ParmVarDecl *Param = (ParmVarDecl *)chunk.Fun.ArgInfo[argIdx].Param;
+ for (unsigned argIdx = 0, e = chunk.Fun.NumArgs; argIdx != e; ++argIdx) {
+ ParmVarDecl *Param =
+ cast<ParmVarDecl>(chunk.Fun.ArgInfo[argIdx].Param.getAs<Decl>());
if (Param->hasUnparsedDefaultArg()) {
CachedTokens *Toks = chunk.Fun.ArgInfo[argIdx].DefaultArgTokens;
Diag(Param->getLocation(), diag::err_param_default_argument_nonfunc)
@@ -381,11 +382,11 @@
/// class foo : public bar, virtual private baz {
/// 'public bar' and 'virtual private baz' are each base-specifiers.
Sema::BaseResult
-Sema::ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange,
+Sema::ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange,
bool Virtual, AccessSpecifier Access,
TypeTy *basetype, SourceLocation BaseLoc) {
AdjustDeclIfTemplate(classdecl);
- CXXRecordDecl *Class = cast<CXXRecordDecl>((Decl*)classdecl);
+ CXXRecordDecl *Class = cast<CXXRecordDecl>(classdecl.getAs<Decl>());
QualType BaseType = QualType::getFromOpaquePtr(basetype);
if (CXXBaseSpecifier *BaseSpec = CheckBaseSpecifier(Class, SpecifierRange,
Virtual, Access,
@@ -451,13 +452,13 @@
/// ActOnBaseSpecifiers - Attach the given base specifiers to the
/// class, after checking whether there are any duplicate base
/// classes.
-void Sema::ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
+void Sema::ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases,
unsigned NumBases) {
if (!ClassDecl || !Bases || !NumBases)
return;
AdjustDeclIfTemplate(ClassDecl);
- AttachBaseSpecifiers(cast<CXXRecordDecl>((Decl*)ClassDecl),
+ AttachBaseSpecifiers(cast<CXXRecordDecl>(ClassDecl.getAs<Decl>()),
(CXXBaseSpecifier**)(Bases), NumBases);
}
@@ -470,10 +471,10 @@
/// bitfield width if there is one and 'InitExpr' specifies the initializer if
/// any. 'LastInGroup' is non-null for cases where one declspec has multiple
/// declarators on it.
-Sema::DeclTy *
+Sema::DeclPtrTy
Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
ExprTy *BW, ExprTy *InitExpr,
- DeclTy *LastInGroup) {
+ DeclPtrTy LastInGroup) {
const DeclSpec &DS = D.getDeclSpec();
DeclarationName Name = GetNameForDeclarator(D);
Expr *BitWidth = static_cast<Expr*>(BW);
@@ -552,7 +553,7 @@
AS);
assert(Member && "HandleField never returns null");
} else {
- Member = static_cast<Decl*>(ActOnDeclarator(S, D, LastInGroup));
+ Member = ActOnDeclarator(S, D, LastInGroup).getAs<Decl>();
if (!Member) {
if (BitWidth) DeleteExpr(BitWidth);
return LastInGroup;
@@ -590,18 +591,18 @@
assert((Name || isInstField) && "No identifier for non-field ?");
if (Init)
- AddInitializerToDecl(Member, ExprArg(*this, Init), false);
+ AddInitializerToDecl(DeclPtrTy::make(Member), ExprArg(*this, Init), false);
if (isInstField) {
FieldCollector->Add(cast<FieldDecl>(Member));
return LastInGroup;
}
- return Member;
+ return DeclPtrTy::make(Member);
}
/// ActOnMemInitializer - Handle a C++ member initializer.
Sema::MemInitResult
-Sema::ActOnMemInitializer(DeclTy *ConstructorD,
+Sema::ActOnMemInitializer(DeclPtrTy ConstructorD,
Scope *S,
IdentifierInfo *MemberOrBase,
SourceLocation IdLoc,
@@ -610,7 +611,7 @@
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
CXXConstructorDecl *Constructor
- = dyn_cast<CXXConstructorDecl>((Decl*)ConstructorD);
+ = dyn_cast<CXXConstructorDecl>(ConstructorD.getAs<Decl>());
if (!Constructor) {
// The user wrote a constructor initializer on a function that is
// not a C++ constructor. Ignore the error for now, because we may
@@ -706,11 +707,11 @@
return new CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, NumArgs);
}
-void Sema::ActOnMemInitializers(DeclTy *ConstructorDecl,
+void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl,
SourceLocation ColonLoc,
MemInitTy **MemInits, unsigned NumMemInits) {
CXXConstructorDecl *Constructor =
- dyn_cast<CXXConstructorDecl>((Decl *)ConstructorDecl);
+ dyn_cast<CXXConstructorDecl>(ConstructorDecl.getAs<Decl>());
if (!Constructor) {
Diag(ColonLoc, diag::err_only_constructors_take_base_inits);
@@ -917,15 +918,15 @@
}
void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
- DeclTy *TagDecl,
+ DeclPtrTy TagDecl,
SourceLocation LBrac,
SourceLocation RBrac) {
TemplateDecl *Template = AdjustDeclIfTemplate(TagDecl);
ActOnFields(S, RLoc, TagDecl,
- (DeclTy**)FieldCollector->getCurFields(),
+ (DeclPtrTy*)FieldCollector->getCurFields(),
FieldCollector->getCurNumFields(), LBrac, RBrac, 0);
- CXXRecordDecl *RD = cast<CXXRecordDecl>((Decl*)TagDecl);
+ CXXRecordDecl *RD = cast<CXXRecordDecl>(TagDecl.getAs<Decl>());
if (!RD->isAbstract()) {
// Collect all the pure virtual methods and see if this is an abstract
// class after all.
@@ -1159,9 +1160,9 @@
/// Method declaration as if we had just parsed the qualified method
/// name. However, it should not bring the parameters into scope;
/// that will be performed by ActOnDelayedCXXMethodParameter.
-void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *MethodD) {
+void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) {
CXXScopeSpec SS;
- FunctionDecl *Method = (FunctionDecl*)MethodD;
+ FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>());
QualType ClassTy
= Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext()));
SS.setScopeRep(
@@ -1174,15 +1175,15 @@
/// function parameter into scope for use in parsing later parts of
/// the method declaration. For example, we could see an
/// ActOnParamDefaultArgument event for this parameter.
-void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *ParamD) {
- ParmVarDecl *Param = (ParmVarDecl*)ParamD;
+void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy ParamD) {
+ ParmVarDecl *Param = cast<ParmVarDecl>(ParamD.getAs<Decl>());
// If this parameter has an unparsed default argument, clear it out
// to make way for the parsed default argument.
if (Param->hasUnparsedDefaultArg())
Param->setDefaultArg(0);
- S->AddDecl(Param);
+ S->AddDecl(DeclPtrTy::make(Param));
if (Param->getDeclName())
IdResolver.AddDecl(Param);
}
@@ -1193,8 +1194,8 @@
/// ActOnStartOfFunctionDef action later (not necessarily
/// immediately!) for this method, if it was also defined inside the
/// class body.
-void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *MethodD) {
- FunctionDecl *Method = (FunctionDecl*)MethodD;
+void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) {
+ FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>());
CXXScopeSpec SS;
QualType ClassTy
= Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext()));
@@ -1483,7 +1484,7 @@
/// the declaration of the given C++ conversion function. This routine
/// is responsible for recording the conversion function in the C++
/// class, if possible.
-Sema::DeclTy *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
+Sema::DeclPtrTy Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
assert(Conversion && "Expected to receive a conversion function declaration");
// Set the lexical context of this conversion function
@@ -1528,14 +1529,14 @@
Conv != ConvEnd; ++Conv) {
if (*Conv == Conversion->getPreviousDeclaration()) {
*Conv = Conversion;
- return (DeclTy *)Conversion;
+ return DeclPtrTy::make(Conversion);
}
}
assert(Conversion->isInvalidDecl() && "Conversion should not get here.");
} else
ClassDecl->addConversionFunction(Context, Conversion);
- return (DeclTy *)Conversion;
+ return DeclPtrTy::make(Conversion);
}
//===----------------------------------------------------------------------===//
@@ -1544,10 +1545,10 @@
/// ActOnStartNamespaceDef - This is called at the start of a namespace
/// definition.
-Sema::DeclTy *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
- SourceLocation IdentLoc,
- IdentifierInfo *II,
- SourceLocation LBrace) {
+Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
+ SourceLocation IdentLoc,
+ IdentifierInfo *II,
+ SourceLocation LBrace) {
NamespaceDecl *Namespc =
NamespaceDecl::Create(Context, CurContext, IdentLoc, II);
Namespc->setLBracLoc(LBrace);
@@ -1573,9 +1574,9 @@
Namespc->setOriginalNamespace(OrigNS->getOriginalNamespace());
// Remove the previous declaration from the scope.
- if (DeclRegionScope->isDeclScope(OrigNS)) {
+ if (DeclRegionScope->isDeclScope(DeclPtrTy::make(OrigNS))) {
IdResolver.RemoveDecl(OrigNS);
- DeclRegionScope->RemoveDecl(OrigNS);
+ DeclRegionScope->RemoveDecl(DeclPtrTy::make(OrigNS));
}
} else if (PrevDecl) {
// This is an invalid name redefinition.
@@ -1597,26 +1598,26 @@
// each DeclContext for the namespace has the declarations
// that showed up in that particular namespace definition.
PushDeclContext(NamespcScope, Namespc);
- return Namespc;
+ return DeclPtrTy::make(Namespc);
}
/// ActOnFinishNamespaceDef - This callback is called after a namespace is
/// exited. Decl is the DeclTy returned by ActOnStartNamespaceDef.
-void Sema::ActOnFinishNamespaceDef(DeclTy *D, SourceLocation RBrace) {
- Decl *Dcl = static_cast<Decl *>(D);
+void Sema::ActOnFinishNamespaceDef(DeclPtrTy D, SourceLocation RBrace) {
+ Decl *Dcl = D.getAs<Decl>();
NamespaceDecl *Namespc = dyn_cast_or_null<NamespaceDecl>(Dcl);
assert(Namespc && "Invalid parameter, expected NamespaceDecl");
Namespc->setRBracLoc(RBrace);
PopDeclContext();
}
-Sema::DeclTy *Sema::ActOnUsingDirective(Scope *S,
- SourceLocation UsingLoc,
- SourceLocation NamespcLoc,
- const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *NamespcName,
- AttributeList *AttrList) {
+Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
+ SourceLocation UsingLoc,
+ SourceLocation NamespcLoc,
+ const CXXScopeSpec &SS,
+ SourceLocation IdentLoc,
+ IdentifierInfo *NamespcName,
+ AttributeList *AttrList) {
assert(!SS.isInvalid() && "Invalid CXXScopeSpec.");
assert(NamespcName && "Invalid NamespcName.");
assert(IdentLoc.isValid() && "Invalid NamespceName location.");
@@ -1629,7 +1630,7 @@
LookupNamespaceName, false);
if (R.isAmbiguous()) {
DiagnoseAmbiguousLookup(R, NamespcName, IdentLoc);
- return 0;
+ return DeclPtrTy();
}
if (NamedDecl *NS = R) {
assert(isa<NamespaceDecl>(NS) && "expected namespace decl");
@@ -1660,7 +1661,7 @@
// FIXME: We ignore attributes for now.
delete AttrList;
- return UDir;
+ return DeclPtrTy::make(UDir);
}
void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) {
@@ -1672,15 +1673,15 @@
else
// Otherwise it is block-sope. using-directives will affect lookup
// only to the end of scope.
- S->PushUsingDirective(UDir);
+ S->PushUsingDirective(DeclPtrTy::make(UDir));
}
-Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S,
- SourceLocation AliasLoc,
- IdentifierInfo *Alias,
- const CXXScopeSpec &SS,
- SourceLocation NamespaceLoc,
- IdentifierInfo *NamespaceName) {
+Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
+ SourceLocation AliasLoc,
+ IdentifierInfo *Alias,
+ const CXXScopeSpec &SS,
+ SourceLocation NamespaceLoc,
+ IdentifierInfo *NamespaceName) {
// Check if we have a previous declaration with the same name.
if (NamedDecl *PrevDecl = LookupName(S, Alias, LookupOrdinaryName)) {
@@ -1690,7 +1691,7 @@
diag::err_redefinition_different_kind;
Diag(AliasLoc, DiagID) << Alias;
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
- return 0;
+ return DeclPtrTy();
}
// Lookup the namespace name.
@@ -1698,33 +1699,33 @@
LookupNamespaceName, false);
if (R.isAmbiguous()) {
DiagnoseAmbiguousLookup(R, NamespaceName, NamespaceLoc);
- return 0;
+ return DeclPtrTy();
}
if (!R) {
Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange();
- return 0;
+ return DeclPtrTy();
}
- return 0;
+ return DeclPtrTy();
}
/// AddCXXDirectInitializerToDecl - This action is called immediately after
/// ActOnDeclarator, when a C++ direct initializer is present.
/// e.g: "int x(1);"
-void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
+void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
+ SourceLocation LParenLoc,
MultiExprArg Exprs,
SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
unsigned NumExprs = Exprs.size();
assert(NumExprs != 0 && Exprs.get() && "missing expressions");
- Decl *RealDecl = static_cast<Decl *>(Dcl);
+ Decl *RealDecl = Dcl.getAs<Decl>();
// If there is no declaration, there was an error parsing it. Just ignore
// the initializer.
- if (RealDecl == 0) {
+ if (RealDecl == 0)
return;
- }
VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
if (!VDecl) {
@@ -2411,12 +2412,12 @@
/// by Lang/StrSize. LBraceLoc, if valid, provides the location of
/// the '{' brace. Otherwise, this linkage specification does not
/// have any braces.
-Sema::DeclTy *Sema::ActOnStartLinkageSpecification(Scope *S,
- SourceLocation ExternLoc,
- SourceLocation LangLoc,
- const char *Lang,
- unsigned StrSize,
- SourceLocation LBraceLoc) {
+Sema::DeclPtrTy Sema::ActOnStartLinkageSpecification(Scope *S,
+ SourceLocation ExternLoc,
+ SourceLocation LangLoc,
+ const char *Lang,
+ unsigned StrSize,
+ SourceLocation LBraceLoc) {
LinkageSpecDecl::LanguageIDs Language;
if (strncmp(Lang, "\"C\"", StrSize) == 0)
Language = LinkageSpecDecl::lang_c;
@@ -2424,7 +2425,7 @@
Language = LinkageSpecDecl::lang_cxx;
else {
Diag(LangLoc, diag::err_bad_language);
- return 0;
+ return DeclPtrTy();
}
// FIXME: Add all the various semantics of linkage specifications
@@ -2434,16 +2435,16 @@
LBraceLoc.isValid());
CurContext->addDecl(D);
PushDeclContext(S, D);
- return D;
+ return DeclPtrTy::make(D);
}
/// ActOnFinishLinkageSpecification - Completely the definition of
/// the C++ linkage specification LinkageSpec. If RBraceLoc is
/// valid, it's the position of the closing '}' brace in a linkage
/// specification that uses braces.
-Sema::DeclTy *Sema::ActOnFinishLinkageSpecification(Scope *S,
- DeclTy *LinkageSpec,
- SourceLocation RBraceLoc) {
+Sema::DeclPtrTy Sema::ActOnFinishLinkageSpecification(Scope *S,
+ DeclPtrTy LinkageSpec,
+ SourceLocation RBraceLoc) {
if (LinkageSpec)
PopDeclContext();
return LinkageSpec;
@@ -2451,8 +2452,7 @@
/// ActOnExceptionDeclarator - Parsed the exception-declarator in a C++ catch
/// handler.
-Sema::DeclTy *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D)
-{
+Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) {
QualType ExDeclType = GetTypeForDeclarator(D, S);
SourceLocation Begin = D.getDeclSpec().getSourceRange().getBegin();
@@ -2497,11 +2497,10 @@
if (NamedDecl *PrevDecl = LookupName(S, II, LookupOrdinaryName)) {
// The scope should be freshly made just for us. There is just no way
// it contains any previous declaration.
- assert(!S->isDeclScope(PrevDecl));
+ assert(!S->isDeclScope(DeclPtrTy::make(PrevDecl)));
if (PrevDecl->isTemplateParameter()) {
// Maybe we will complain about the shadowed template parameter.
DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl);
-
}
}
@@ -2517,17 +2516,17 @@
}
// Add the exception declaration into this scope.
- S->AddDecl(ExDecl);
+ S->AddDecl(DeclPtrTy::make(ExDecl));
if (II)
IdResolver.AddDecl(ExDecl);
ProcessDeclAttributes(ExDecl, D);
- return ExDecl;
+ return DeclPtrTy::make(ExDecl);
}
-Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
- ExprArg assertexpr,
- ExprArg assertmessageexpr) {
+Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
+ ExprArg assertexpr,
+ ExprArg assertmessageexpr) {
Expr *AssertExpr = (Expr *)assertexpr.get();
StringLiteral *AssertMessage =
cast<StringLiteral>((Expr *)assertmessageexpr.get());
@@ -2537,7 +2536,7 @@
if (!AssertExpr->isIntegerConstantExpr(Value, Context)) {
Diag(AssertLoc, diag::err_static_assert_expression_is_not_constant) <<
AssertExpr->getSourceRange();
- return 0;
+ return DeclPtrTy();
}
if (Value == 0) {
@@ -2554,11 +2553,11 @@
AssertExpr, AssertMessage);
CurContext->addDecl(Decl);
- return Decl;
+ return DeclPtrTy::make(Decl);
}
-void Sema::SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc) {
- Decl *Dcl = static_cast<Decl*>(dcl);
+void Sema::SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc) {
+ Decl *Dcl = dcl.getAs<Decl>();
FunctionDecl *Fn = dyn_cast<FunctionDecl>(Dcl);
if (!Fn) {
Diag(DelLoc, diag::err_deleted_non_function);
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index ba35333..8809eb9 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -20,9 +20,9 @@
/// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible
/// and user declared, in the method definition's AST.
-void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclTy *D) {
+void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) {
assert(getCurMethodDecl() == 0 && "Method parsing confused");
- ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>((Decl *)D);
+ ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>(D.getAs<Decl>());
// If we don't have a valid method decl, simply return.
if (!MDecl)
@@ -53,11 +53,11 @@
PushOnScopeChains(*PI, FnBodyScope);
}
-Sema::DeclTy *Sema::
+Sema::DeclPtrTy Sema::
ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperName, SourceLocation SuperLoc,
- DeclTy * const *ProtoRefs, unsigned NumProtoRefs,
+ const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs,
SourceLocation EndProtoLoc, AttributeList *AttrList) {
assert(ClassName && "Missing class identifier");
@@ -85,7 +85,7 @@
// Return the previous class interface.
// FIXME: don't leak the objects passed in!
- return IDecl;
+ return DeclPtrTy::make(IDecl);
} else {
IDecl->setLocation(AtInterfaceLoc);
IDecl->setForwardDecl(false);
@@ -100,7 +100,7 @@
// FIXME: PushOnScopeChains
CurContext->addDecl(IDecl);
// Remember that this needs to be removed when the scope is popped.
- TUScope->AddDecl(IDecl);
+ TUScope->AddDecl(DeclPtrTy::make(IDecl));
}
if (SuperName) {
@@ -160,16 +160,16 @@
}
CheckObjCDeclScope(IDecl);
- return IDecl;
+ return DeclPtrTy::make(IDecl);
}
/// ActOnCompatiblityAlias - this action is called after complete parsing of
/// @compatibility_alias declaration. It sets up the alias relationships.
-Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
- IdentifierInfo *AliasName,
- SourceLocation AliasLocation,
- IdentifierInfo *ClassName,
- SourceLocation ClassLocation) {
+Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
+ IdentifierInfo *AliasName,
+ SourceLocation AliasLocation,
+ IdentifierInfo *ClassName,
+ SourceLocation ClassLocation) {
// Look for previous declaration of alias name
NamedDecl *ADecl = LookupName(TUScope, AliasName, LookupOrdinaryName);
if (ADecl) {
@@ -178,7 +178,7 @@
else
Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
Diag(ADecl->getLocation(), diag::note_previous_declaration);
- return 0;
+ return DeclPtrTy();
}
// Check for class declaration
NamedDecl *CDeclU = LookupName(TUScope, ClassName, LookupOrdinaryName);
@@ -196,7 +196,7 @@
Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
if (CDeclU)
Diag(CDeclU->getLocation(), diag::note_previous_declaration);
- return 0;
+ return DeclPtrTy();
}
// Everything checked out, instantiate a new alias declaration AST.
@@ -208,9 +208,9 @@
// FIXME: PushOnScopeChains?
CurContext->addDecl(AliasDecl);
if (!CheckObjCDeclScope(AliasDecl))
- TUScope->AddDecl(AliasDecl);
+ TUScope->AddDecl(DeclPtrTy::make(AliasDecl));
- return AliasDecl;
+ return DeclPtrTy::make(AliasDecl);
}
void Sema::CheckForwardProtocolDeclarationForCircularDependency(
@@ -232,11 +232,11 @@
}
}
-Sema::DeclTy *
+Sema::DeclPtrTy
Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName,
SourceLocation ProtocolLoc,
- DeclTy * const *ProtoRefs,
+ const DeclPtrTy *ProtoRefs,
unsigned NumProtoRefs,
SourceLocation EndProtoLoc,
AttributeList *AttrList) {
@@ -251,7 +251,7 @@
Diag(PDecl->getLocation(), diag::note_previous_definition);
// Just return the protocol we already had.
// FIXME: don't leak the objects passed in!
- return PDecl;
+ return DeclPtrTy::make(PDecl);
}
ObjCList<ObjCProtocolDecl> PList;
PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context);
@@ -279,7 +279,7 @@
}
CheckObjCDeclScope(PDecl);
- return PDecl;
+ return DeclPtrTy::make(PDecl);
}
/// FindProtocolDeclaration - This routine looks up protocols and
@@ -289,7 +289,7 @@
Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
unsigned NumProtocols,
- llvm::SmallVectorImpl<DeclTy*> &Protocols) {
+ llvm::SmallVectorImpl<DeclPtrTy> &Protocols) {
for (unsigned i = 0; i != NumProtocols; ++i) {
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first];
if (!PDecl) {
@@ -305,7 +305,7 @@
if (WarnOnDeclarations && PDecl->isForwardDecl())
Diag(ProtocolId[i].second, diag::warn_undef_protocolref)
<< ProtocolId[i].first;
- Protocols.push_back(PDecl);
+ Protocols.push_back(DeclPtrTy::make(PDecl));
}
}
@@ -428,8 +428,8 @@
/// inherited protocol into the list of properties for class/category 'CDecl'
///
void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl,
- DeclTy *MergeItsProtocols) {
- Decl *ClassDecl = static_cast<Decl *>(MergeItsProtocols);
+ DeclPtrTy MergeItsProtocols) {
+ Decl *ClassDecl = MergeItsProtocols.getAs<Decl>();
ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl);
if (!IDecl) {
@@ -446,12 +446,12 @@
// their properties into this class as well.
for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(),
E = CatDecl->protocol_end(); P != E; ++P)
- MergeProtocolPropertiesIntoClass(CatDecl, *P);
+ MergeProtocolPropertiesIntoClass(CatDecl, DeclPtrTy::make(*P));
} else {
ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
E = MD->protocol_end(); P != E; ++P)
- MergeOneProtocolPropertiesIntoClass(CatDecl, (*P));
+ MergeOneProtocolPropertiesIntoClass(CatDecl, *P);
}
return;
}
@@ -466,12 +466,12 @@
// their properties into this class as well.
for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(),
E = IDecl->protocol_end(); P != E; ++P)
- MergeProtocolPropertiesIntoClass(IDecl, *P);
+ MergeProtocolPropertiesIntoClass(IDecl, DeclPtrTy::make(*P));
} else {
ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
E = MD->protocol_end(); P != E; ++P)
- MergeOneProtocolPropertiesIntoClass(IDecl, (*P));
+ MergeOneProtocolPropertiesIntoClass(IDecl, *P);
}
}
@@ -505,7 +505,7 @@
}
/// ActOnForwardProtocolDeclaration -
-Action::DeclTy *
+Action::DeclPtrTy
Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
const IdentifierLocPair *IdentList,
unsigned NumElts,
@@ -531,15 +531,15 @@
&Protocols[0], Protocols.size());
CurContext->addDecl(PDecl);
CheckObjCDeclScope(PDecl);
- return PDecl;
+ return DeclPtrTy::make(PDecl);
}
-Sema::DeclTy *Sema::
+Sema::DeclPtrTy Sema::
ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName,
SourceLocation CategoryLoc,
- DeclTy * const *ProtoRefs,
+ const DeclPtrTy *ProtoRefs,
unsigned NumProtoRefs,
SourceLocation EndProtoLoc) {
ObjCCategoryDecl *CDecl =
@@ -552,7 +552,7 @@
if (!IDecl || IDecl->isForwardDecl()) {
CDecl->setInvalidDecl();
Diag(ClassLoc, diag::err_undef_interface) << ClassName;
- return CDecl;
+ return DeclPtrTy::make(CDecl);
}
CDecl->setClassInterface(IDecl);
@@ -580,13 +580,13 @@
}
CheckObjCDeclScope(CDecl);
- return CDecl;
+ return DeclPtrTy::make(CDecl);
}
/// ActOnStartCategoryImplementation - Perform semantic checks on the
/// category implementation declaration and build an ObjCCategoryImplDecl
/// object.
-Sema::DeclTy *Sema::ActOnStartCategoryImplementation(
+Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation(
SourceLocation AtCatImplLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CatName, SourceLocation CatLoc) {
@@ -606,10 +606,10 @@
ObjCCategoryImpls.push_back(CDecl);
CheckObjCDeclScope(CDecl);
- return CDecl;
+ return DeclPtrTy::make(CDecl);
}
-Sema::DeclTy *Sema::ActOnStartClassImplementation(
+Sema::DeclPtrTy Sema::ActOnStartClassImplementation(
SourceLocation AtClassImplLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperClassname,
@@ -666,7 +666,7 @@
// FIXME: PushOnScopeChains?
CurContext->addDecl(IDecl);
// Remember that this needs to be removed when the scope is popped.
- TUScope->AddDecl(IDecl);
+ TUScope->AddDecl(DeclPtrTy::make(IDecl));
}
ObjCImplementationDecl* IMPDecl =
@@ -677,7 +677,7 @@
CurContext->addDecl(IMPDecl);
if (CheckObjCDeclScope(IMPDecl))
- return IMPDecl;
+ return DeclPtrTy::make(IMPDecl);
// Check that there is no duplicate implementation of this class.
if (ObjCImplementations[ClassName])
@@ -685,7 +685,7 @@
Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
else // add it to the list.
ObjCImplementations[ClassName] = IMPDecl;
- return IMPDecl;
+ return DeclPtrTy::make(IMPDecl);
}
void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
@@ -957,7 +957,7 @@
}
/// ActOnForwardClassDeclaration -
-Action::DeclTy *
+Action::DeclPtrTy
Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentifierInfo **IdentList,
unsigned NumElts) {
@@ -995,7 +995,7 @@
// FIXME: PushOnScopeChains?
CurContext->addDecl(IDecl);
// Remember that this needs to be removed when the scope is popped.
- TUScope->AddDecl(IDecl);
+ TUScope->AddDecl(DeclPtrTy::make(IDecl));
}
Interfaces.push_back(IDecl);
@@ -1006,7 +1006,7 @@
Interfaces.size());
CurContext->addDecl(CDecl);
CheckObjCDeclScope(CDecl);
- return CDecl;
+ return DeclPtrTy::make(CDecl);
}
@@ -1231,12 +1231,12 @@
// Note: For class/category implemenations, allMethods/allProperties is
// always null.
-void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
- DeclTy **allMethods, unsigned allNum,
- DeclTy **allProperties, unsigned pNum,
- DeclTy **allTUVars,
+void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl,
+ DeclPtrTy *allMethods, unsigned allNum,
+ DeclPtrTy *allProperties, unsigned pNum,
+ DeclPtrTy *allTUVars,
unsigned tuvNum) {
- Decl *ClassDecl = static_cast<Decl *>(classDecl);
+ Decl *ClassDecl = classDecl.getAs<Decl>();
// FIXME: If we don't have a ClassDecl, we have an error. We should consider
// always passing in a decl. If the decl has an error, isInvalidDecl()
@@ -1257,7 +1257,7 @@
for (unsigned i = 0; i < allNum; i++ ) {
ObjCMethodDecl *Method =
- cast_or_null<ObjCMethodDecl>(static_cast<Decl*>(allMethods[i]));
+ cast_or_null<ObjCMethodDecl>(allMethods[i].getAs<Decl>());
if (!Method) continue; // Already issued a diagnostic.
if (Method->isInstanceMethod()) {
@@ -1299,14 +1299,14 @@
// Compares properties declared in this class to those of its
// super class.
ComparePropertiesInBaseAndSuper(I);
- MergeProtocolPropertiesIntoClass(I, I);
+ MergeProtocolPropertiesIntoClass(I, DeclPtrTy::make(I));
} else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
// Categories are used to extend the class by declaring new methods.
// By the same token, they are also used to add new properties. No
// need to compare the added property to those in the class.
// Merge protocol properties into category
- MergeProtocolPropertiesIntoClass(C, C);
+ MergeProtocolPropertiesIntoClass(C, DeclPtrTy::make(C));
if (C->getIdentifier() == 0)
DiagnoseClassExtensionDupMethods(C, C->getClassInterface());
}
@@ -1341,7 +1341,7 @@
}
if (isInterfaceDeclKind)
for (unsigned i = 0; i < tuvNum; i++) {
- if (VarDecl *VDecl = dyn_cast<VarDecl>((Decl*)allTUVars[i])) {
+ if (VarDecl *VDecl = dyn_cast<VarDecl>(allTUVars[i].getAs<Decl>())) {
if (VDecl->getStorageClass() != VarDecl::Extern &&
VDecl->getStorageClass() != VarDecl::PrivateExtern) {
NamedDecl *ClassNameDecl = dyn_cast<NamedDecl>(ClassDecl);
@@ -1374,9 +1374,9 @@
return ret;
}
-Sema::DeclTy *Sema::ActOnMethodDeclaration(
+Sema::DeclPtrTy Sema::ActOnMethodDeclaration(
SourceLocation MethodLoc, SourceLocation EndLoc,
- tok::TokenKind MethodType, DeclTy *classDecl,
+ tok::TokenKind MethodType, DeclPtrTy classDecl,
ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Selector Sel,
// optional arguments. The number of types/arguments is obtained
@@ -1385,12 +1385,12 @@
llvm::SmallVectorImpl<Declarator> &Cdecls,
AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
bool isVariadic) {
- Decl *ClassDecl = static_cast<Decl*>(classDecl);
+ Decl *ClassDecl = classDecl.getAs<Decl>();
// Make sure we can establish a context for the method.
if (!ClassDecl) {
Diag(MethodLoc, diag::error_missing_method_context);
- return 0;
+ return DeclPtrTy();
}
QualType resultDeclType;
@@ -1402,7 +1402,7 @@
if (resultDeclType->isObjCInterfaceType()) {
Diag(MethodLoc, diag::err_object_cannot_be_by_value)
<< "returned";
- return 0;
+ return DeclPtrTy();
}
} else // get the type for "id".
resultDeclType = Context.getObjCIdType();
@@ -1436,7 +1436,7 @@
Diag(MethodLoc, diag::err_object_cannot_be_by_value)
<< "passed";
ObjCMethod->setInvalidDecl();
- return 0;
+ return DeclPtrTy();
}
} else
argType = Context.getObjCIdType();
@@ -1495,7 +1495,7 @@
<< ObjCMethod->getDeclName();
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
}
- return ObjCMethod;
+ return DeclPtrTy::make(ObjCMethod);
}
void Sema::CheckObjCPropertyAttributes(QualType PropertyTy,
@@ -1571,14 +1571,14 @@
}
}
-Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
- FieldDeclarator &FD,
- ObjCDeclSpec &ODS,
- Selector GetterSel,
- Selector SetterSel,
- DeclTy *ClassCategory,
- bool *isOverridingProperty,
- tok::ObjCKeywordKind MethodImplKind) {
+Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
+ FieldDeclarator &FD,
+ ObjCDeclSpec &ODS,
+ Selector GetterSel,
+ Selector SetterSel,
+ DeclPtrTy ClassCategory,
+ bool *isOverridingProperty,
+ tok::ObjCKeywordKind MethodImplKind) {
unsigned Attributes = ODS.getPropertyAttributes();
bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) ||
// default is readwrite!
@@ -1590,7 +1590,7 @@
!(Attributes & ObjCDeclSpec::DQ_PR_retain) &&
!(Attributes & ObjCDeclSpec::DQ_PR_copy)));
QualType T = GetTypeForDeclarator(FD.D, S);
- Decl *ClassDecl = static_cast<Decl *>(ClassCategory);
+ Decl *ClassDecl = ClassCategory.getAs<Decl>();
// May modify Attributes.
CheckObjCPropertyAttributes(T, AtLoc, Attributes);
@@ -1632,7 +1632,7 @@
else
Diag(AtLoc, diag::err_use_continuation_class) << ICDecl->getDeclName();
*isOverridingProperty = true;
- return 0;
+ return DeclPtrTy();
}
// No matching property found in the main class. Just fall thru
// and add property to the anonymous category. It looks like
@@ -1641,7 +1641,7 @@
} else {
Diag(CDecl->getLocation(), diag::err_continuation_class);
*isOverridingProperty = true;
- return 0;
+ return DeclPtrTy();
}
}
@@ -1691,24 +1691,24 @@
else if (MethodImplKind == tok::objc_optional)
PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
- return PDecl;
+ return DeclPtrTy::make(PDecl);
}
/// ActOnPropertyImplDecl - This routine performs semantic checks and
/// builds the AST node for a property implementation declaration; declared
/// as @synthesize or @dynamic.
///
-Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
- SourceLocation PropertyLoc,
- bool Synthesize,
- DeclTy *ClassCatImpDecl,
- IdentifierInfo *PropertyId,
- IdentifierInfo *PropertyIvar) {
- Decl *ClassImpDecl = static_cast<Decl*>(ClassCatImpDecl);
+Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
+ SourceLocation PropertyLoc,
+ bool Synthesize,
+ DeclPtrTy ClassCatImpDecl,
+ IdentifierInfo *PropertyId,
+ IdentifierInfo *PropertyIvar) {
+ Decl *ClassImpDecl = ClassCatImpDecl.getAs<Decl>();
// Make sure we have a context for the property implementation declaration.
if (!ClassImpDecl) {
Diag(AtLoc, diag::error_missing_property_context);
- return 0;
+ return DeclPtrTy();
}
ObjCPropertyDecl *property = 0;
ObjCInterfaceDecl* IDecl = 0;
@@ -1727,18 +1727,18 @@
property = IDecl->FindPropertyDeclaration(PropertyId);
if (!property) {
Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName();
- return 0;
+ return DeclPtrTy();
}
}
else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
if (Synthesize) {
Diag(AtLoc, diag::error_synthesize_category_decl);
- return 0;
+ return DeclPtrTy();
}
IDecl = CatImplClass->getClassInterface();
if (!IDecl) {
Diag(AtLoc, diag::error_missing_property_interface);
- return 0;
+ return DeclPtrTy();
}
ObjCCategoryDecl *Category =
IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
@@ -1746,18 +1746,17 @@
// If category for this implementation not found, it is an error which
// has already been reported eralier.
if (!Category)
- return 0;
+ return DeclPtrTy();
// Look for this property declaration in @implementation's category
property = Category->FindPropertyDeclaration(PropertyId);
if (!property) {
Diag(PropertyLoc, diag::error_bad_category_property_decl)
<< Category->getDeclName();
- return 0;
+ return DeclPtrTy();
}
- }
- else {
+ } else {
Diag(AtLoc, diag::error_bad_property_context);
- return 0;
+ return DeclPtrTy();
}
ObjCIvarDecl *Ivar = 0;
// Check that we have a valid, previously declared ivar for @synthesize
@@ -1773,7 +1772,7 @@
<< PropertyId;
else
Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
- return 0;
+ return DeclPtrTy();
}
QualType PropType = Context.getCanonicalType(property->getType());
QualType IvarType = Context.getCanonicalType(Ivar->getType());
@@ -1783,40 +1782,37 @@
if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) {
Diag(PropertyLoc, diag::error_property_ivar_type)
<< property->getDeclName() << Ivar->getDeclName();
- return 0;
+ return DeclPtrTy();
}
- else {
- // FIXME! Rules for properties are somewhat different that those
- // for assignments. Use a new routine to consolidate all cases;
- // specifically for property redeclarations as well as for ivars.
- QualType lhsType =
- Context.getCanonicalType(PropType).getUnqualifiedType();
- QualType rhsType =
- Context.getCanonicalType(IvarType).getUnqualifiedType();
- if (lhsType != rhsType &&
- lhsType->isArithmeticType()) {
- Diag(PropertyLoc, diag::error_property_ivar_type)
- << property->getDeclName() << Ivar->getDeclName();
- return 0;
- }
- // __weak is explicit. So it works on Canonical type.
- if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak()) {
- Diag(PropertyLoc, diag::error_weak_property)
- << property->getDeclName() << Ivar->getDeclName();
- return 0;
- }
- if ((Context.isObjCObjectPointerType(property->getType()) ||
- PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak()) {
- Diag(PropertyLoc, diag::error_strong_property)
- << property->getDeclName() << Ivar->getDeclName();
- return 0;
- }
+
+ // FIXME! Rules for properties are somewhat different that those
+ // for assignments. Use a new routine to consolidate all cases;
+ // specifically for property redeclarations as well as for ivars.
+ QualType lhsType =Context.getCanonicalType(PropType).getUnqualifiedType();
+ QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
+ if (lhsType != rhsType &&
+ lhsType->isArithmeticType()) {
+ Diag(PropertyLoc, diag::error_property_ivar_type)
+ << property->getDeclName() << Ivar->getDeclName();
+ return DeclPtrTy();
+ }
+ // __weak is explicit. So it works on Canonical type.
+ if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak()) {
+ Diag(PropertyLoc, diag::error_weak_property)
+ << property->getDeclName() << Ivar->getDeclName();
+ return DeclPtrTy();
+ }
+ if ((Context.isObjCObjectPointerType(property->getType()) ||
+ PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak()) {
+ Diag(PropertyLoc, diag::error_strong_property)
+ << property->getDeclName() << Ivar->getDeclName();
+ return DeclPtrTy();
}
}
} else if (PropertyIvar) {
// @dynamic
Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
- return 0;
+ return DeclPtrTy();
}
assert (property && "ActOnPropertyImplDecl - property declaration missing");
ObjCPropertyImplDecl *PIDecl =
@@ -1840,7 +1836,7 @@
if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) {
Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
- return 0;
+ return DeclPtrTy();
}
IC->addPropertyImplementation(PIDecl);
}
@@ -1858,12 +1854,12 @@
CatImplClass->FindPropertyImplDecl(PropertyId)) {
Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
- return 0;
+ return DeclPtrTy();
}
CatImplClass->addPropertyImplementation(PIDecl);
}
- return PIDecl;
+ return DeclPtrTy::make(PIDecl);
}
bool Sema::CheckObjCDeclScope(Decl *D) {
@@ -1882,28 +1878,26 @@
/// part of the AST generation logic of @defs.
static void CollectIvars(ObjCInterfaceDecl *Class, RecordDecl *Record,
ASTContext& Ctx,
- llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) {
+ llvm::SmallVectorImpl<Sema::DeclPtrTy> &ivars) {
if (Class->getSuperClass())
CollectIvars(Class->getSuperClass(), Record, Ctx, ivars);
// For each ivar, create a fresh ObjCAtDefsFieldDecl.
- for (ObjCInterfaceDecl::ivar_iterator
- I=Class->ivar_begin(), E=Class->ivar_end(); I!=E; ++I) {
-
+ for (ObjCInterfaceDecl::ivar_iterator I = Class->ivar_begin(),
+ E = Class->ivar_end(); I != E; ++I) {
ObjCIvarDecl* ID = *I;
- ivars.push_back(ObjCAtDefsFieldDecl::Create(Ctx, Record,
- ID->getLocation(),
- ID->getIdentifier(),
- ID->getType(),
- ID->getBitWidth()));
+ Decl *FD = ObjCAtDefsFieldDecl::Create(Ctx, Record, ID->getLocation(),
+ ID->getIdentifier(), ID->getType(),
+ ID->getBitWidth());
+ ivars.push_back(Sema::DeclPtrTy::make(FD));
}
}
/// Called whenever @defs(ClassName) is encountered in the source. Inserts the
/// instance variables of ClassName into Decls.
-void Sema::ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
+void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart,
IdentifierInfo *ClassName,
- llvm::SmallVectorImpl<DeclTy*> &Decls) {
+ llvm::SmallVectorImpl<DeclPtrTy> &Decls) {
// Check that ClassName is a valid class
ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);
if (!Class) {
@@ -1911,15 +1905,15 @@
return;
}
// Collect the instance variables
- CollectIvars(Class, dyn_cast<RecordDecl>((Decl*)TagD), Context, Decls);
+ CollectIvars(Class, dyn_cast<RecordDecl>(TagD.getAs<Decl>()), Context, Decls);
// Introduce all of these fields into the appropriate scope.
- for (llvm::SmallVectorImpl<DeclTy*>::iterator D = Decls.begin();
+ for (llvm::SmallVectorImpl<DeclPtrTy>::iterator D = Decls.begin();
D != Decls.end(); ++D) {
- FieldDecl *FD = cast<FieldDecl>((Decl*)*D);
+ FieldDecl *FD = cast<FieldDecl>(D->getAs<Decl>());
if (getLangOptions().CPlusPlus)
PushOnScopeChains(cast<FieldDecl>(FD), S);
- else if (RecordDecl *Record = dyn_cast<RecordDecl>((Decl*)TagD))
+ else if (RecordDecl *Record = dyn_cast<RecordDecl>(TagD.getAs<Decl>()))
Record->addDecl(FD);
}
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0a77c21..39d2a50 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -876,7 +876,7 @@
Scope *CheckS = S;
while (CheckS) {
if (CheckS->isWithinElse() &&
- CheckS->getControlParent()->isDeclScope(Var)) {
+ CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) {
if (Var->getType()->isBooleanType())
ExprError(Diag(Loc, diag::warn_value_always_false)
<< Var->getDeclName());
@@ -1743,7 +1743,7 @@
Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
tok::TokenKind OpKind, SourceLocation MemberLoc,
IdentifierInfo &Member,
- DeclTy *ObjCImpDecl) {
+ DeclPtrTy ObjCImpDecl) {
Expr *BaseExpr = static_cast<Expr *>(Base.release());
assert(BaseExpr && "no record expression");
@@ -1879,7 +1879,7 @@
// the context as argument to this routine. Ideally, this context need
// be passed down in the AST node and somehow calculated from the AST
// for a function decl.
- Decl *ImplDecl = static_cast<Decl *>(ObjCImpDecl);
+ Decl *ImplDecl = ObjCImpDecl.getAs<Decl>();
if (ObjCImplementationDecl *IMPD =
dyn_cast<ObjCImplementationDecl>(ImplDecl))
ClassOfMethodDecl = IMPD->getClassInterface();
@@ -4590,13 +4590,13 @@
// no arguments, not a function that takes a single void argument.
if (FTI.hasPrototype &&
FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 &&
- (!((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType().getCVRQualifiers() &&
- ((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType()->isVoidType())) {
+ (!FTI.ArgInfo[0].Param.getAs<ParmVarDecl>()->getType().getCVRQualifiers()&&
+ FTI.ArgInfo[0].Param.getAs<ParmVarDecl>()->getType()->isVoidType())) {
// empty arg list, don't push any params.
CurBlock->isVariadic = false;
} else if (FTI.hasPrototype) {
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
- CurBlock->Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param);
+ CurBlock->Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
CurBlock->isVariadic = FTI.isVariadic;
QualType T = GetTypeForDeclarator (ParamInfo, CurScope);
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index a6cb24c..361434a 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -664,26 +664,28 @@
} else if (const RecordType *RT = Ty->getAsRecordType()) {
RecordDecl *RD = RT->getDecl();
// The type-specifier-seq shall not declare a new class...
- if (RD->isDefinition() && (RD->getIdentifier() == 0 || S->isDeclScope(RD)))
+ if (RD->isDefinition() &&
+ (RD->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(RD))))
Diag(RD->getLocation(), diag::err_type_defined_in_condition);
} else if (const EnumType *ET = Ty->getAsEnumType()) {
EnumDecl *ED = ET->getDecl();
// ...or enumeration.
- if (ED->isDefinition() && (ED->getIdentifier() == 0 || S->isDeclScope(ED)))
+ if (ED->isDefinition() &&
+ (ED->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(ED))))
Diag(ED->getLocation(), diag::err_type_defined_in_condition);
}
- DeclTy *Dcl = ActOnDeclarator(S, D, 0);
+ DeclPtrTy Dcl = ActOnDeclarator(S, D, DeclPtrTy());
if (!Dcl)
return ExprError();
AddInitializerToDecl(Dcl, move(AssignExprVal));
// Mark this variable as one that is declared within a conditional.
- if (VarDecl *VD = dyn_cast<VarDecl>((Decl *)Dcl))
- VD->setDeclaredInCondition(true);
-
- return Owned(new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc,
- cast<VarDecl>(static_cast<Decl *>(Dcl))));
+ // We know that the decl had to be a VarDecl because that is the only type of
+ // decl that can be assigned and the grammar requires an '='.
+ VarDecl *VD = cast<VarDecl>(Dcl.getAs<Decl>());
+ VD->setDeclaredInCondition(true);
+ return Owned(new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc, VD));
}
/// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 770f930..69bd560 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -84,12 +84,11 @@
AddNamespaceUsingDirectives(Ctx, UDirs, /*ref*/ VisitedNS);
} else {
- Scope::udir_iterator
- I = S->using_directives_begin(),
- End = S->using_directives_end();
+ Scope::udir_iterator I = S->using_directives_begin(),
+ End = S->using_directives_end();
for (; I != End; ++I) {
- UsingDirectiveDecl * UD = static_cast<UsingDirectiveDecl*>(*I);
+ UsingDirectiveDecl *UD = I->getAs<UsingDirectiveDecl>();
UDirs.push_back(UD);
std::push_heap(UDirs.begin(), UDirs.end(), UsingDirAncestorCompare());
@@ -575,7 +574,7 @@
//
for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) {
// Check whether the IdResolver has anything in this scope.
- for (; I != IEnd && S->isDeclScope(*I); ++I) {
+ for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
if (isAcceptableLookupResult(*I, NameKind, IDNS)) {
// We found something. Look for anything else in our scope
// with this same name and in an acceptable identifier
@@ -583,7 +582,7 @@
// need to.
IdentifierResolver::iterator LastI = I;
for (++LastI; LastI != IEnd; ++LastI) {
- if (!S->isDeclScope(*LastI))
+ if (!S->isDeclScope(DeclPtrTy::make(*LastI)))
break;
}
LookupResult Result =
@@ -666,7 +665,7 @@
"We should have been looking only at file context here already.");
// Check whether the IdResolver has anything in this scope.
- for (; I != IEnd && S->isDeclScope(*I); ++I) {
+ for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
if (isAcceptableLookupResult(*I, NameKind, IDNS)) {
// We found something. Look for anything else in our scope
// with this same name and in an acceptable identifier
@@ -674,7 +673,7 @@
// need to.
IdentifierResolver::iterator LastI = I;
for (++LastI; LastI != IEnd; ++LastI) {
- if (!S->isDeclScope(*LastI))
+ if (!S->isDeclScope(DeclPtrTy::make(*LastI)))
break;
}
@@ -790,7 +789,7 @@
if (NameKind == LookupRedeclarationWithLinkage) {
// Determine whether this (or a previous) declaration is
// out-of-scope.
- if (!LeftStartingScope && !S->isDeclScope(*I))
+ if (!LeftStartingScope && !S->isDeclScope(DeclPtrTy::make(*I)))
LeftStartingScope = true;
// If we found something outside of our starting scope that
@@ -804,14 +803,15 @@
// might have a set of overloaded functions.
// Figure out what scope the identifier is in.
- while (!(S->getFlags() & Scope::DeclScope) || !S->isDeclScope(*I))
+ while (!(S->getFlags() & Scope::DeclScope) ||
+ !S->isDeclScope(DeclPtrTy::make(*I)))
S = S->getParent();
// Find the last declaration in this scope (with the same
// name, naturally).
IdentifierResolver::iterator LastI = I;
for (++LastI; LastI != IEnd; ++LastI) {
- if (!S->isDeclScope(*LastI))
+ if (!S->isDeclScope(DeclPtrTy::make(*LastI)))
break;
}
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 025a245..ca6d7fe 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -4323,7 +4323,7 @@
Method->getResultType().getNonReferenceType(),
OpLoc);
return ActOnMemberReferenceExpr(S, ExprArg(*this, Base), OpLoc, tok::arrow,
- MemberLoc, Member).release();
+ MemberLoc, Member, DeclPtrTy()).release();
}
/// FixOverloadedFunctionReference - E is an expression that refers to
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 4082d48..b331911 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -37,14 +37,13 @@
return Owned(new (Context) NullStmt(SemiLoc));
}
-Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl,
+Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclPtrTy decl,
SourceLocation StartLoc,
SourceLocation EndLoc) {
- if (decl == 0)
+ Decl *D = decl.getAs<Decl>();
+ if (D == 0)
return StmtError();
- Decl *D = static_cast<Decl *>(decl);
-
// This is a temporary hack until we are always passing around
// DeclGroupRefs.
llvm::SmallVector<Decl*, 10> decls;
@@ -1001,10 +1000,10 @@
Action::OwningStmtResult
Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
- SourceLocation RParen, DeclTy *Parm,
+ SourceLocation RParen, DeclPtrTy Parm,
StmtArg Body, StmtArg catchList) {
Stmt *CatchList = static_cast<Stmt*>(catchList.release());
- ParmVarDecl *PVD = static_cast<ParmVarDecl*>(Parm);
+ ParmVarDecl *PVD = cast_or_null<ParmVarDecl>(Parm.getAs<Decl>());
// PVD == 0 implies @catch(...).
if (PVD) {
@@ -1071,11 +1070,11 @@
/// ActOnCXXCatchBlock - Takes an exception declaration and a handler block
/// and creates a proper catch handler from them.
Action::OwningStmtResult
-Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclTy *ExDecl,
+Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclPtrTy ExDecl,
StmtArg HandlerBlock) {
// There's nothing to test that ActOnExceptionDecl didn't already test.
return Owned(new (Context) CXXCatchStmt(CatchLoc,
- static_cast<VarDecl*>(ExDecl),
+ cast_or_null<VarDecl>(ExDecl.getAs<Decl>()),
static_cast<Stmt*>(HandlerBlock.release())));
}
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 6994697..773a2b1 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -27,21 +27,19 @@
/// passed to indicate the C++ scope in which the identifier will be
/// found.
TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S,
- DeclTy *&Template,
+ DeclPtrTy &Template,
const CXXScopeSpec *SS) {
NamedDecl *IIDecl = LookupParsedName(S, SS, &II, LookupOrdinaryName);
if (IIDecl) {
if (isa<TemplateDecl>(IIDecl)) {
- Template = IIDecl;
+ Template = DeclPtrTy::make(IIDecl);
if (isa<FunctionTemplateDecl>(IIDecl))
return TNK_Function_template;
- else if (isa<ClassTemplateDecl>(IIDecl))
+ if (isa<ClassTemplateDecl>(IIDecl))
return TNK_Class_template;
- else if (isa<TemplateTemplateParmDecl>(IIDecl))
- return TNK_Template_template_parm;
- else
- assert(false && "Unknown TemplateDecl");
+ assert(isa<TemplateTemplateParmDecl>(IIDecl) && "Unknown TemplateDecl");
+ return TNK_Template_template_parm;
} else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(IIDecl)) {
// C++ [temp.local]p1:
// Like normal (non-template) classes, class templates have an
@@ -56,11 +54,11 @@
// specialization.
if (Record->isInjectedClassName()) {
Record = cast<CXXRecordDecl>(Context.getCanonicalDecl(Record));
- if ((Template = Record->getDescribedClassTemplate()))
+ if ((Template = DeclPtrTy::make(Record->getDescribedClassTemplate())))
return TNK_Class_template;
- else if (ClassTemplateSpecializationDecl *Spec
+ if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(Record)) {
- Template = Spec->getSpecializedTemplate();
+ Template = DeclPtrTy::make(Spec->getSpecializedTemplate());
return TNK_Class_template;
}
}
@@ -69,7 +67,7 @@
// FIXME: What follows is a gross hack.
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(IIDecl)) {
if (FD->getType()->isDependentType()) {
- Template = FD;
+ Template = DeclPtrTy::make(FD);
return TNK_Function_template;
}
} else if (OverloadedFunctionDecl *Ovl
@@ -78,7 +76,7 @@
FEnd = Ovl->function_end();
F != FEnd; ++F) {
if ((*F)->getType()->isDependentType()) {
- Template = Ovl;
+ Template = DeclPtrTy::make(Ovl);
return TNK_Function_template;
}
}
@@ -110,10 +108,9 @@
/// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
/// the parameter D to reference the templated declaration and return a pointer
/// to the template declaration. Otherwise, do nothing to D and return null.
-TemplateDecl *Sema::AdjustDeclIfTemplate(DeclTy *&D)
-{
- if(TemplateDecl *Temp = dyn_cast<TemplateDecl>(static_cast<Decl*>(D))) {
- D = Temp->getTemplatedDecl();
+TemplateDecl *Sema::AdjustDeclIfTemplate(DeclPtrTy &D) {
+ if (TemplateDecl *Temp = dyn_cast<TemplateDecl>(D.getAs<Decl>())) {
+ D = DeclPtrTy::make(Temp->getTemplatedDecl());
return Temp;
}
return 0;
@@ -128,11 +125,11 @@
/// ParamName is the location of the parameter name (if any).
/// If the type parameter has a default argument, it will be added
/// later via ActOnTypeParameterDefault.
-Sema::DeclTy *Sema::ActOnTypeParameter(Scope *S, bool Typename,
- SourceLocation KeyLoc,
- IdentifierInfo *ParamName,
- SourceLocation ParamNameLoc,
- unsigned Depth, unsigned Position) {
+Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename,
+ SourceLocation KeyLoc,
+ IdentifierInfo *ParamName,
+ SourceLocation ParamNameLoc,
+ unsigned Depth, unsigned Position) {
assert(S->isTemplateParamScope() &&
"Template type parameter not in template parameter scope!");
bool Invalid = false;
@@ -156,21 +153,21 @@
if (ParamName) {
// Add the template parameter into the current scope.
- S->AddDecl(Param);
+ S->AddDecl(DeclPtrTy::make(Param));
IdResolver.AddDecl(Param);
}
- return Param;
+ return DeclPtrTy::make(Param);
}
/// ActOnTypeParameterDefault - Adds a default argument (the type
/// Default) to the given template type parameter (TypeParam).
-void Sema::ActOnTypeParameterDefault(DeclTy *TypeParam,
+void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam,
SourceLocation EqualLoc,
SourceLocation DefaultLoc,
TypeTy *DefaultT) {
TemplateTypeParmDecl *Parm
- = cast<TemplateTypeParmDecl>(static_cast<Decl *>(TypeParam));
+ = cast<TemplateTypeParmDecl>(TypeParam.getAs<Decl>());
QualType Default = QualType::getFromOpaquePtr(DefaultT);
// C++ [temp.param]p14:
@@ -234,9 +231,9 @@
/// template parameter (e.g., "int Size" in "template<int Size>
/// class Array") has been parsed. S is the current scope and D is
/// the parsed declarator.
-Sema::DeclTy *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
- unsigned Depth,
- unsigned Position) {
+Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
+ unsigned Depth,
+ unsigned Position) {
QualType T = GetTypeForDeclarator(D, S);
assert(S->isTemplateParamScope() &&
@@ -265,19 +262,19 @@
if (D.getIdentifier()) {
// Add the template parameter into the current scope.
- S->AddDecl(Param);
+ S->AddDecl(DeclPtrTy::make(Param));
IdResolver.AddDecl(Param);
}
- return Param;
+ return DeclPtrTy::make(Param);
}
/// \brief Adds a default argument to the given non-type template
/// parameter.
-void Sema::ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParamD,
+void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD,
SourceLocation EqualLoc,
ExprArg DefaultE) {
NonTypeTemplateParmDecl *TemplateParm
- = cast<NonTypeTemplateParmDecl>(static_cast<Decl *>(TemplateParamD));
+ = cast<NonTypeTemplateParmDecl>(TemplateParamD.getAs<Decl>());
Expr *Default = static_cast<Expr *>(DefaultE.get());
// C++ [temp.param]p14:
@@ -297,13 +294,13 @@
/// ActOnTemplateTemplateParameter - Called when a C++ template template
/// parameter (e.g. T in template <template <typename> class T> class array)
/// has been parsed. S is the current scope.
-Sema::DeclTy *Sema::ActOnTemplateTemplateParameter(Scope* S,
- SourceLocation TmpLoc,
- TemplateParamsTy *Params,
- IdentifierInfo *Name,
- SourceLocation NameLoc,
- unsigned Depth,
- unsigned Position)
+Sema::DeclPtrTy Sema::ActOnTemplateTemplateParameter(Scope* S,
+ SourceLocation TmpLoc,
+ TemplateParamsTy *Params,
+ IdentifierInfo *Name,
+ SourceLocation NameLoc,
+ unsigned Depth,
+ unsigned Position)
{
assert(S->isTemplateParamScope() &&
"Template template parameter not in template parameter scope!");
@@ -326,20 +323,20 @@
// If the tt-param has a name, then link the identifier into the scope
// and lookup mechanisms.
if (Name) {
- S->AddDecl(Param);
+ S->AddDecl(DeclPtrTy::make(Param));
IdResolver.AddDecl(Param);
}
- return Param;
+ return DeclPtrTy::make(Param);
}
/// \brief Adds a default argument to the given template template
/// parameter.
-void Sema::ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParamD,
+void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD,
SourceLocation EqualLoc,
ExprArg DefaultE) {
TemplateTemplateParmDecl *TemplateParm
- = cast<TemplateTemplateParmDecl>(static_cast<Decl *>(TemplateParamD));
+ = cast<TemplateTemplateParmDecl>(TemplateParamD.getAs<Decl>());
// Since a template-template parameter's default argument is an
// id-expression, it must be a DeclRefExpr.
@@ -374,7 +371,7 @@
SourceLocation ExportLoc,
SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
- DeclTy **Params, unsigned NumParams,
+ DeclPtrTy *Params, unsigned NumParams,
SourceLocation RAngleLoc) {
if (ExportLoc.isValid())
Diag(ExportLoc, diag::note_template_export_unsupported);
@@ -522,7 +519,7 @@
NewTemplate->setInvalidDecl();
NewClass->setInvalidDecl();
}
- return NewTemplate;
+ return DeclPtrTy::make(NewTemplate);
}
/// \brief Checks the validity of a template parameter list, possibly
@@ -774,13 +771,13 @@
}
Action::TypeResult
-Sema::ActOnClassTemplateId(DeclTy *TemplateD, SourceLocation TemplateLoc,
+Sema::ActOnClassTemplateId(DeclPtrTy TemplateD, SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgsIn,
SourceLocation *TemplateArgLocs,
SourceLocation RAngleLoc,
const CXXScopeSpec *SS) {
- TemplateDecl *Template = cast<TemplateDecl>(static_cast<Decl *>(TemplateD));
+ TemplateDecl *Template = cast<TemplateDecl>(TemplateD.getAs<Decl>());
ClassTemplateDecl *ClassTemplate = cast<ClassTemplateDecl>(Template);
// Translate the parser's template argument list in our AST format.
@@ -1798,7 +1795,7 @@
Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
SourceLocation KWLoc,
const CXXScopeSpec &SS,
- DeclTy *TemplateD,
+ DeclPtrTy TemplateD,
SourceLocation TemplateNameLoc,
SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgsIn,
@@ -1808,7 +1805,7 @@
MultiTemplateParamsArg TemplateParameterLists) {
// Find the class template we're specializing
ClassTemplateDecl *ClassTemplate
- = dyn_cast_or_null<ClassTemplateDecl>(static_cast<Decl *>(TemplateD));
+ = dyn_cast_or_null<ClassTemplateDecl>(TemplateD.getAs<Decl>());
if (!ClassTemplate)
return true;
@@ -1823,14 +1820,17 @@
else {
TemplateParameterList *TemplateParams
= static_cast<TemplateParameterList*>(*TemplateParameterLists.get());
- if (TemplateParameterLists.size() > 1)
- return Diag(TemplateParams->getTemplateLoc(),
- diag::err_template_spec_extra_headers);
+ if (TemplateParameterLists.size() > 1) {
+ Diag(TemplateParams->getTemplateLoc(),
+ diag::err_template_spec_extra_headers);
+ return true;
+ }
- if (TemplateParams->size() > 0)
+ if (TemplateParams->size() > 0) {
// FIXME: No support for class template partial specialization.
- return Diag(TemplateParams->getTemplateLoc(),
- diag::unsup_template_partial_spec);
+ Diag(TemplateParams->getTemplateLoc(), diag::unsup_template_partial_spec);
+ return true;
+ }
}
// Check that the specialization uses the same tag kind as the
@@ -1962,7 +1962,7 @@
// be seen when iterating through the list of declarations in that
// context. However, specializations are not found by name lookup.
CurContext->addDecl(Specialization);
- return Specialization;
+ return DeclPtrTy::make(Specialization);
}
Sema::TypeResult
@@ -1974,9 +1974,6 @@
return true;
QualType T = CheckTypenameType(NNS, II, SourceRange(TypenameLoc, IdLoc));
- if (T.isNull())
- return 0;
-
return T.getAsOpaquePtr();
}
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index b274f87..2578703 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -715,17 +715,16 @@
NumTemplateArgs))
Invalid = true;
- llvm::SmallVector<DeclTy *, 32> Fields;
+ llvm::SmallVector<DeclPtrTy, 32> Fields;
for (RecordDecl::decl_iterator Member = Pattern->decls_begin(),
- MemberEnd = Pattern->decls_end();
- Member != MemberEnd; ++Member) {
+ MemberEnd = Pattern->decls_end(); Member != MemberEnd; ++Member) {
Decl *NewMember = InstantiateDecl(*Member, Instantiation,
TemplateArgs, NumTemplateArgs);
if (NewMember) {
if (NewMember->isInvalidDecl())
Invalid = true;
else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember))
- Fields.push_back(Field);
+ Fields.push_back(DeclPtrTy::make(Field));
} else {
// FIXME: Eventually, a NULL return will mean that one of the
// instantiations was a semantic disaster, and we'll want to set
@@ -735,7 +734,7 @@
}
// Finish checking fields.
- ActOnFields(0, Instantiation->getLocation(), Instantiation,
+ ActOnFields(0, Instantiation->getLocation(), DeclPtrTy::make(Instantiation),
&Fields[0], Fields.size(), SourceLocation(), SourceLocation(),
0);
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index adddb29..e7210b3 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -20,8 +20,7 @@
namespace {
class VISIBILITY_HIDDEN TemplateDeclInstantiator
- : public DeclVisitor<TemplateDeclInstantiator, Decl *>
- {
+ : public DeclVisitor<TemplateDeclInstantiator, Decl *> {
Sema &SemaRef;
DeclContext *Owner;
const TemplateArgument *TemplateArgs;
@@ -136,7 +135,7 @@
if (Init.isInvalid())
Var->setInvalidDecl();
else
- SemaRef.AddInitializerToDecl(Var, move(Init),
+ SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init),
D->hasCXXDirectInitializer());
}
@@ -204,9 +203,9 @@
OwningExprResult Message = SemaRef.Clone(D->getMessage());
Decl *StaticAssert
- = (Decl *)SemaRef.ActOnStaticAssertDeclaration(D->getLocation(),
- move(InstantiatedAssertExpr),
- move(Message));
+ = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(),
+ move(InstantiatedAssertExpr),
+ move(Message)).getAs<Decl>();
return StaticAssert;
}
@@ -218,7 +217,7 @@
Owner->addDecl(Enum);
Enum->startDefinition();
- llvm::SmallVector<Sema::DeclTy *, 16> Enumerators;
+ llvm::SmallVector<Sema::DeclPtrTy, 16> Enumerators;
EnumConstantDecl *LastEnumConst = 0;
for (EnumDecl::enumerator_iterator EC = D->enumerator_begin(),
@@ -250,12 +249,12 @@
if (EnumConst) {
Enum->addDecl(EnumConst);
- Enumerators.push_back(EnumConst);
+ Enumerators.push_back(Sema::DeclPtrTy::make(EnumConst));
LastEnumConst = EnumConst;
}
}
- SemaRef.ActOnEnumBody(Enum->getLocation(), Enum,
+ SemaRef.ActOnEnumBody(Enum->getLocation(), Sema::DeclPtrTy::make(Enum),
&Enumerators[0], Enumerators.size());
return Enum;
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 21254ea..b8969a2 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -707,7 +707,8 @@
llvm::SmallVector<QualType, 16> ArgTys;
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
- ParmVarDecl *Param = (ParmVarDecl *)FTI.ArgInfo[i].Param;
+ ParmVarDecl *Param =
+ cast<ParmVarDecl>(FTI.ArgInfo[i].Param.getAs<Decl>());
QualType ArgTy = Param->getType();
assert(!ArgTy.isNull() && "Couldn't parse type?");
@@ -849,8 +850,8 @@
/// ObjCGetTypeForMethodDefinition - Builds the type for a method definition
/// declarator
-QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) {
- ObjCMethodDecl *MDecl = cast<ObjCMethodDecl>(static_cast<Decl *>(D));
+QualType Sema::ObjCGetTypeForMethodDefinition(DeclPtrTy D) {
+ ObjCMethodDecl *MDecl = cast<ObjCMethodDecl>(D.getAs<Decl>());
QualType T = MDecl->getResultType();
llvm::SmallVector<QualType, 16> ArgTys;