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/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp
index 776d701..049228f 100644
--- a/lib/Parse/MinimalAction.cpp
+++ b/lib/Parse/MinimalAction.cpp
@@ -26,19 +26,19 @@
 Action::~Action() {}
 
 // Defined out-of-line here because of dependecy on AttributeList
-Action::DeclTy *Action::ActOnUsingDirective(Scope *CurScope,
-                                            SourceLocation UsingLoc,
-                                            SourceLocation NamespcLoc,
-                                            const CXXScopeSpec &SS,
-                                            SourceLocation IdentLoc,
-                                            IdentifierInfo *NamespcName,
-                                            AttributeList *AttrList) {
+Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope,
+                                              SourceLocation UsingLoc,
+                                              SourceLocation NamespcLoc,
+                                              const CXXScopeSpec &SS,
+                                              SourceLocation IdentLoc,
+                                              IdentifierInfo *NamespcName,
+                                              AttributeList *AttrList) {
   
   // FIXME: Parser seems to assume that Action::ActOn* takes ownership over
   // passed AttributeList, however other actions don't free it, is it
   // temporary state or bug?
   delete AttrList;
-  return 0;
+  return DeclPtrTy();
 }
 
 
@@ -135,7 +135,7 @@
 
 TemplateNameKind 
 MinimalAction::isTemplateName(IdentifierInfo &II, Scope *S,
-                              DeclTy *&TemplateDecl,
+                              DeclPtrTy &TemplateDecl,
                               const CXXScopeSpec *SS) {
   return TNK_Non_template;
 }
@@ -143,12 +143,12 @@
 /// ActOnDeclarator - If this is a typedef declarator, we modify the
 /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
 /// popped.
-Action::DeclTy *
-MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
+Action::DeclPtrTy
+MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy LastInGroup) {
   IdentifierInfo *II = D.getIdentifier();
   
   // If there is no identifier associated with this declarator, bail out.
-  if (II == 0) return 0;
+  if (II == 0) return DeclPtrTy();
   
   TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo<TypeNameInfo>();
   bool isTypeName =
@@ -162,29 +162,29 @@
     getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II);
   
     // Remember that this needs to be removed when the scope is popped.
-    S->AddDecl(II);
+    S->AddDecl(DeclPtrTy::make(II));
   } 
-  return 0;
+  return DeclPtrTy();
 }
 
-Action::DeclTy *
+Action::DeclPtrTy
 MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
                                         IdentifierInfo *ClassName,
                                         SourceLocation ClassLoc,
                                         IdentifierInfo *SuperName,
                                         SourceLocation SuperLoc,
-                                        DeclTy * const *ProtoRefs,
+                                        const DeclPtrTy *ProtoRefs,
                                         unsigned NumProtocols,
                                         SourceLocation EndProtoLoc,
                                         AttributeList *AttrList) {
   // Allocate and add the 'TypeNameInfo' "decl".
   getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName);
-  return 0;
+  return DeclPtrTy();
 }
 
 /// ActOnForwardClassDeclaration - 
 /// Scope will always be top level file scope. 
-Action::DeclTy *
+Action::DeclPtrTy
 MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
                                 IdentifierInfo **IdentList, unsigned NumElts) {
   for (unsigned i = 0; i != NumElts; ++i) {
@@ -192,9 +192,9 @@
     getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]);
   
     // Remember that this needs to be removed when the scope is popped.
-    TUScope->AddDecl(IdentList[i]);
+    TUScope->AddDecl(DeclPtrTy::make(IdentList[i]));
   }
-  return 0;
+  return DeclPtrTy();
 }
 
 /// ActOnPopScope - When a scope is popped, if any typedefs are now
@@ -204,7 +204,7 @@
   
   for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
        I != E; ++I) {
-    IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
+    IdentifierInfo &II = *(*I).getAs<IdentifierInfo>();
     TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>();
     assert(TI && "This decl didn't get pushed??");