[cfe-commits] r111800 - in /cfe/trunk: include/clang/Parse/Parser.h include/clang/Sema/Ownership.h include/clang/Sema/ParsedTemplate.h lib/Parse/ParseAST.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTemplate.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaTemplate.cpp
John McCall
rjmccall at apple.com
Mon Aug 23 00:28:44 PDT 2010
Author: rjmccall
Date: Mon Aug 23 02:28:44 2010
New Revision: 111800
URL: http://llvm.org/viewvc/llvm-project?rev=111800&view=rev
Log:
Push DeclGroupRefs and TemplateNames in an opaque but type-safe way
through the parser.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Ownership.h
cfe/trunk/include/clang/Sema/ParsedTemplate.h
cfe/trunk/lib/Parse/ParseAST.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Aug 23 02:28:44 2010
@@ -27,6 +27,7 @@
struct CXX0XAttributeList;
class PragmaHandler;
class Scope;
+ class DeclGroupRef;
class DiagnosticBuilder;
class Parser;
class PragmaUnusedHandler;
@@ -147,13 +148,13 @@
// different actual classes based on the actions in place.
typedef Expr ExprTy;
typedef Stmt StmtTy;
- typedef Action::DeclGroupPtrTy DeclGroupPtrTy;
+ typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
typedef Action::TypeTy TypeTy;
typedef CXXBaseSpecifier BaseTy;
typedef CXXBaseOrMemberInitializer MemInitTy;
typedef NestedNameSpecifier CXXScopeTy;
typedef TemplateParameterList TemplateParamsTy;
- typedef Action::TemplateTy TemplateTy;
+ typedef OpaquePtr<TemplateName> TemplateTy;
typedef llvm::SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
Modified: cfe/trunk/include/clang/Sema/Ownership.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Ownership.h?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Ownership.h (original)
+++ cfe/trunk/include/clang/Sema/Ownership.h Mon Aug 23 02:28:44 2010
@@ -27,59 +27,64 @@
class CXXBaseOrMemberInitializer;
class CXXBaseSpecifier;
class Decl;
+ class DeclGroupRef;
class Expr;
class NestedNameSpecifier;
class Stmt;
+ class TemplateName;
class TemplateParameterList;
/// OpaquePtr - 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 UID
/// template argument is used to make sure that "Decl" pointers are not
/// compatible with "Type" pointers for example.
- template<int UID>
+ template <class PtrTy>
class OpaquePtr {
void *Ptr;
+ explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
+
public:
OpaquePtr() : Ptr(0) {}
- template <typename T>
- T* getAs() const {
- return llvm::PointerLikeTypeTraits<T*>::getFromVoidPointer(Ptr);
+ static OpaquePtr make(PtrTy P) {
+ OpaquePtr OP; OP.set(P); return OP;
}
- template <typename T>
- T getAsVal() const {
- return llvm::PointerLikeTypeTraits<T>::getFromVoidPointer(Ptr);
+ template <typename T> T* getAs() const {
+ return get();
}
- void *get() const { return Ptr; }
+ template <typename T> T getAsVal() const {
+ return get();
+ }
- template<typename T>
- static OpaquePtr make(T P) {
- OpaquePtr R; R.set(P); return R;
+ PtrTy get() const {
+ return llvm::PointerLikeTypeTraits<PtrTy>::getFromVoidPointer(Ptr);
}
- template<typename T>
- void set(T P) {
- Ptr = llvm::PointerLikeTypeTraits<T>::getAsVoidPointer(P);
+ void set(PtrTy P) {
+ Ptr = llvm::PointerLikeTypeTraits<PtrTy>::getAsVoidPointer(P);
}
operator bool() const { return Ptr != 0; }
+
+ void *getAsOpaquePtr() const { return Ptr; }
+ static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
};
}
namespace llvm {
- template <int UID>
- class PointerLikeTypeTraits<clang::OpaquePtr<UID> > {
+ template <class T>
+ class PointerLikeTypeTraits<clang::OpaquePtr<T> > {
public:
- static inline void *getAsVoidPointer(clang::OpaquePtr<UID> P) {
+ static inline void *getAsVoidPointer(clang::OpaquePtr<T> P) {
// FIXME: Doesn't work? return P.getAs< void >();
- return P.get();
+ return P.getAsOpaquePtr();
}
- static inline clang::OpaquePtr<UID> getFromVoidPointer(void *P) {
- return clang::OpaquePtr<UID>::make(P);
+ static inline clang::OpaquePtr<T> getFromVoidPointer(void *P) {
+ return clang::OpaquePtr<T>::getFromOpaquePtr(P);
}
- enum { NumLowBitsAvailable = 3 };
+ enum { NumLowBitsAvailable = 0 };
};
}
@@ -207,8 +212,8 @@
// Types - Though these don't actually enforce strong typing, they document
// what types are required to be identical for the actions.
- typedef OpaquePtr<1> DeclGroupPtrTy;
- typedef OpaquePtr<2> TemplateTy;
+ typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
+ typedef OpaquePtr<TemplateName> TemplateTy;
typedef Attr AttrTy;
typedef CXXBaseSpecifier BaseTy;
typedef CXXBaseOrMemberInitializer MemInitTy;
@@ -535,6 +540,7 @@
typedef ActionBase::ActionResult<CXXBaseOrMemberInitializer*> MemInitResult;
typedef ActionBase::ActionResult<Decl*> DeclResult;
+ typedef OpaquePtr<TemplateName> ParsedTemplateTy;
}
#endif
Modified: cfe/trunk/include/clang/Sema/ParsedTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedTemplate.h?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/ParsedTemplate.h (original)
+++ cfe/trunk/include/clang/Sema/ParsedTemplate.h Mon Aug 23 02:28:44 2010
@@ -54,7 +54,8 @@
ParsedTemplateArgument(const CXXScopeSpec &SS,
ActionBase::TemplateTy Template,
SourceLocation TemplateLoc)
- : Kind(ParsedTemplateArgument::Template), Arg(Template.get()),
+ : Kind(ParsedTemplateArgument::Template),
+ Arg(Template.getAsOpaquePtr()),
Loc(TemplateLoc), SS(SS) { }
/// \brief Determine whether the given template argument is invalid.
@@ -78,7 +79,7 @@
/// \brief Retrieve the template template argument's template name.
ActionBase::TemplateTy getAsTemplate() const {
assert(Kind == Template && "Not a template template argument");
- return ActionBase::TemplateTy::make(Arg);
+ return ActionBase::TemplateTy::getFromOpaquePtr(Arg);
}
/// \brief Retrieve the location of the template argument.
@@ -128,8 +129,8 @@
OverloadedOperatorKind Operator;
/// The declaration of the template corresponding to the
- /// template-name. This is an Action::TemplateTy.
- void *Template;
+ /// template-name.
+ ParsedTemplateTy Template;
/// The kind of template that Template refers to.
TemplateNameKind Kind;
Modified: cfe/trunk/lib/Parse/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseAST.cpp (original)
+++ cfe/trunk/lib/Parse/ParseAST.cpp Mon Aug 23 02:28:44 2010
@@ -84,11 +84,11 @@
// is due to a top-level semicolon, an action override, or a parse error
// skipping something.
if (ADecl)
- Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
+ Consumer->HandleTopLevelDecl(ADecl.get());
};
// Check for any pending objective-c implementation decl.
while ((ADecl = P.FinishPendingObjCActions()))
- Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
+ Consumer->HandleTopLevelDecl(ADecl.get());
// Process any TopLevelDecls generated by #pragma weak.
for (llvm::SmallVector<Decl*,2>::iterator
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Aug 23 02:28:44 2010
@@ -842,7 +842,7 @@
TagType,
StartLoc,
SS,
- TemplateTy::make(TemplateId->Template),
+ TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
@@ -857,7 +857,7 @@
(TUK == Action::TUK_Friend &&
TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
TypeResult
- = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
+ = Actions.ActOnTemplateIdType(TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
@@ -904,7 +904,7 @@
TagOrTempResult
= Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK,
StartLoc, SS,
- TemplateTy::make(TemplateId->Template),
+ TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Aug 23 02:28:44 2010
@@ -1128,7 +1128,7 @@
TemplateId->TemplateNameLoc = Id.StartLocation;
}
- TemplateId->Template = Template.getAs<void*>();
+ TemplateId->Template = Template;
TemplateId->Kind = TNK;
TemplateId->LAngleLoc = LAngleLoc;
TemplateId->RAngleLoc = RAngleLoc;
Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Mon Aug 23 02:28:44 2010
@@ -806,7 +806,7 @@
TemplateId->Name = 0;
TemplateId->Operator = TemplateName.OperatorFunctionId.Operator;
}
- TemplateId->Template = Template.getAs<void*>();
+ TemplateId->Template = Template;
TemplateId->Kind = TNK;
TemplateId->LAngleLoc = LAngleLoc;
TemplateId->RAngleLoc = RAngleLoc;
@@ -851,7 +851,7 @@
TemplateId->NumArgs);
Action::TypeResult Type
- = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
+ = Actions.ActOnTemplateIdType(TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 23 02:28:44 2010
@@ -2072,8 +2072,7 @@
}
case UnqualifiedId::IK_TemplateId: {
- TemplateName TName
- = TemplateName::getFromVoidPointer(Name.TemplateId->Template);
+ TemplateName TName = Name.TemplateId->Template.get();
SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc;
return Context.getNameForTemplate(TName, TNameLoc);
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Aug 23 02:28:44 2010
@@ -671,8 +671,7 @@
SemaRef.translateTemplateArguments(TemplateArgsPtr, Buffer);
TemplateArgsPtr.release();
- TemplateName TName =
- Sema::TemplateTy::make(Id.TemplateId->Template).getAsVal<TemplateName>();
+ TemplateName TName = Id.TemplateId->Template.get();
SourceLocation TNameLoc = Id.TemplateId->TemplateNameLoc;
NameInfo = SemaRef.Context.getNameForTemplate(TName, TNameLoc);
TemplateArgs = &Buffer;
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Aug 23 02:28:44 2010
@@ -2977,7 +2977,7 @@
ASTTemplateArgsPtr TemplateArgsPtr(*this,
TemplateId->getTemplateArgs(),
TemplateId->NumArgs);
- TypeResult T = ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
+ TypeResult T = ActOnTemplateIdType(TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
@@ -3025,7 +3025,7 @@
ASTTemplateArgsPtr TemplateArgsPtr(*this,
TemplateId->getTemplateArgs(),
TemplateId->NumArgs);
- TypeResult T = ActOnTemplateIdType(TemplateTy::make(TemplateId->Template),
+ TypeResult T = ActOnTemplateIdType(TemplateId->Template,
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=111800&r1=111799&r2=111800&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Aug 23 02:28:44 2010
@@ -436,8 +436,7 @@
}
case ParsedTemplateArgument::Template: {
- TemplateName Template
- = TemplateName::getFromVoidPointer(Arg.getAsTemplate().get());
+ TemplateName Template = Arg.getAsTemplate().get();
return TemplateArgumentLoc(TemplateArgument(Template),
Arg.getScopeSpec().getRange(),
Arg.getLocation());
More information about the cfe-commits
mailing list