Cleanup of OpaquePtr. No functionality changes.

- Some documenation were added.
- Usages of OpaquePtr<A>.getAsVal<A>() were replaced by OpaquePtr<A>.get().
- Methods getAs and getAsVal were renamed to getPtrTo and getPtrAs respectively.

llvm-svn: 189346
This commit is contained in:
Serge Pavlov
2013-08-27 13:15:56 +00:00
parent 54c83368a5
commit 9ddb76e201
7 changed files with 29 additions and 15 deletions

View File

@@ -33,8 +33,12 @@ namespace clang {
class TemplateName; class TemplateName;
class TemplateParameterList; class TemplateParameterList;
/// OpaquePtr - This is a very simple POD type that wraps a pointer that the /// \brief Wrapper for void* pointer.
/// Parser doesn't know about but that Sema or another client does. The UID /// \tparam PtrTy Either a pointer type like 'T*' or a type that behaves like
/// a pointer.
///
/// This is a very simple POD type that wraps a pointer that the Parser
/// doesn't know about but that Sema or another client does. The PtrTy
/// template argument is used to make sure that "Decl" pointers are not /// template argument is used to make sure that "Decl" pointers are not
/// compatible with "Type" pointers for example. /// compatible with "Type" pointers for example.
template <class PtrTy> template <class PtrTy>
@@ -49,11 +53,21 @@ namespace clang {
static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; } static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
template <typename T> T* getAs() const { /// \brief Returns plain pointer to the entity pointed by this wrapper.
/// \tparam PointeeT Type of pointed entity.
///
/// It is identical to getPtrAs<PointeeT*>.
template <typename PointeeT> PointeeT* getPtrTo() const {
return get(); return get();
} }
template <typename T> T getAsVal() const { /// \brief Returns pointer converted to the specified type.
/// \tparam PtrT Result pointer type. There must be implicit conversion
/// from PtrTy to PtrT.
///
/// In contrast to getPtrTo, this method allows the return type to be
/// a smart pointer.
template <typename PtrT> PtrT getPtrAs() const {
return get(); return get();
} }

View File

@@ -5670,7 +5670,7 @@ void Sema::CodeCompleteObjCForCollection(Scope *S,
Data.ObjCCollection = true; Data.ObjCCollection = true;
if (IterationVar.getAsOpaquePtr()) { if (IterationVar.getAsOpaquePtr()) {
DeclGroupRef DG = IterationVar.getAsVal<DeclGroupRef>(); DeclGroupRef DG = IterationVar.get();
for (DeclGroupRef::iterator I = DG.begin(), End = DG.end(); I != End; ++I) { for (DeclGroupRef::iterator I = DG.begin(), End = DG.end(); I != End; ++I) {
if (*I) if (*I)
Data.IgnoreDecls.push_back(*I); Data.IgnoreDecls.push_back(*I);

View File

@@ -442,7 +442,7 @@ bool Sema::DiagnoseUnknownTypeName(IdentifierInfo *&II,
if (isTemplateName(S, SS ? *SS : EmptySS, /*hasTemplateKeyword=*/false, if (isTemplateName(S, SS ? *SS : EmptySS, /*hasTemplateKeyword=*/false,
Name, ParsedType(), true, TemplateResult, Name, ParsedType(), true, TemplateResult,
MemberOfUnknownSpecialization) == TNK_Type_template) { MemberOfUnknownSpecialization) == TNK_Type_template) {
TemplateName TplName = TemplateResult.getAsVal<TemplateName>(); TemplateName TplName = TemplateResult.get();
Diag(IILoc, diag::err_template_missing_args) << TplName; Diag(IILoc, diag::err_template_missing_args) << TplName;
if (TemplateDecl *TplDecl = TplName.getAsTemplateDecl()) { if (TemplateDecl *TplDecl = TplName.getAsTemplateDecl()) {
Diag(TplDecl->getLocation(), diag::note_template_decl_here) Diag(TplDecl->getLocation(), diag::note_template_decl_here)

View File

@@ -2680,7 +2680,7 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef<Decl *> allMethods,
if (isInterfaceDeclKind) { if (isInterfaceDeclKind) {
// Reject invalid vardecls. // Reject invalid vardecls.
for (unsigned i = 0, e = allTUVars.size(); i != e; i++) { for (unsigned i = 0, e = allTUVars.size(); i != e; i++) {
DeclGroupRef DG = allTUVars[i].getAsVal<DeclGroupRef>(); DeclGroupRef DG = allTUVars[i].get();
for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
if (VarDecl *VDecl = dyn_cast<VarDecl>(*I)) { if (VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
if (!VDecl->hasExternalStorage()) if (!VDecl->hasExternalStorage())
@@ -2691,7 +2691,7 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef<Decl *> allMethods,
ActOnObjCContainerFinishDefinition(); ActOnObjCContainerFinishDefinition();
for (unsigned i = 0, e = allTUVars.size(); i != e; i++) { for (unsigned i = 0, e = allTUVars.size(); i != e; i++) {
DeclGroupRef DG = allTUVars[i].getAsVal<DeclGroupRef>(); DeclGroupRef DG = allTUVars[i].get();
for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
(*I)->setTopLevelDeclInObjCContainer(); (*I)->setTopLevelDeclInObjCContainer();
Consumer.HandleTopLevelDeclInObjCContainer(DG); Consumer.HandleTopLevelDeclInObjCContainer(DG);

View File

@@ -65,7 +65,7 @@ StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc,
StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc, StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc,
SourceLocation EndLoc) { SourceLocation EndLoc) {
DeclGroupRef DG = dg.getAsVal<DeclGroupRef>(); DeclGroupRef DG = dg.get();
// If we have an invalid decl, just return an error. // If we have an invalid decl, just return an error.
if (DG.isNull()) return StmtError(); if (DG.isNull()) return StmtError();
@@ -74,7 +74,7 @@ StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc,
} }
void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) {
DeclGroupRef DG = dg.getAsVal<DeclGroupRef>(); DeclGroupRef DG = dg.get();
// If we don't have a declaration, or we have an invalid declaration, // If we don't have a declaration, or we have an invalid declaration,
// just return. // just return.

View File

@@ -2113,7 +2113,7 @@ Sema::ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
if (SS.isInvalid()) if (SS.isInvalid())
return true; return true;
TemplateName Template = TemplateD.getAsVal<TemplateName>(); TemplateName Template = TemplateD.get();
// Translate the parser's template argument list in our AST format. // Translate the parser's template argument list in our AST format.
TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc); TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
@@ -2180,7 +2180,7 @@ TypeResult Sema::ActOnTagTemplateIdType(TagUseKind TUK,
SourceLocation LAngleLoc, SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgsIn, ASTTemplateArgsPtr TemplateArgsIn,
SourceLocation RAngleLoc) { SourceLocation RAngleLoc) {
TemplateName Template = TemplateD.getAsVal<TemplateName>(); TemplateName Template = TemplateD.get();
// Translate the parser's template argument list in our AST format. // Translate the parser's template argument list in our AST format.
TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc); TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
@@ -5680,7 +5680,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
? TemplateParameterLists[0]->getTemplateLoc() : SourceLocation(); ? TemplateParameterLists[0]->getTemplateLoc() : SourceLocation();
// Find the class template we're specializing // Find the class template we're specializing
TemplateName Name = TemplateD.getAsVal<TemplateName>(); TemplateName Name = TemplateD.get();
ClassTemplateDecl *ClassTemplate ClassTemplateDecl *ClassTemplate
= dyn_cast_or_null<ClassTemplateDecl>(Name.getAsTemplateDecl()); = dyn_cast_or_null<ClassTemplateDecl>(Name.getAsTemplateDecl());
@@ -6793,7 +6793,7 @@ Sema::ActOnExplicitInstantiation(Scope *S,
SourceLocation RAngleLoc, SourceLocation RAngleLoc,
AttributeList *Attr) { AttributeList *Attr) {
// Find the class template we're specializing // Find the class template we're specializing
TemplateName Name = TemplateD.getAsVal<TemplateName>(); TemplateName Name = TemplateD.get();
TemplateDecl *TD = Name.getAsTemplateDecl(); TemplateDecl *TD = Name.getAsTemplateDecl();
// Check that the specialization uses the same tag kind as the // Check that the specialization uses the same tag kind as the
// original template. // original template.

View File

@@ -9484,7 +9484,7 @@ TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
ParsedType::make(ObjectType), ParsedType::make(ObjectType),
/*EnteringContext=*/false, /*EnteringContext=*/false,
Template); Template);
return Template.template getAsVal<TemplateName>(); return Template.get();
} }
template<typename Derived> template<typename Derived>