Initial stab at a generalized operation for determining the
instantiation of a declaration from the template version (or version
that lives in a template) and a given set of template arguments. This
needs much, much more testing, but it suffices for simple examples
like

  typedef T* iterator;
  iterator begin();




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72461 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 2528431..3014a8e 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2138,7 +2138,7 @@
     /// this template instantiation.
     Sema &SemaRef;
 
-    /// \brief A mapping from local variable declarations that occur
+    /// \brief A mapping from local declarations that occur
     /// within a template to their instantiations.
     ///
     /// This mapping is used during instantiation to keep track of,
@@ -2152,7 +2152,7 @@
     /// when we instantiate add<int>, we will introduce a mapping from
     /// the ParmVarDecl for 'x' that occurs in the template to the
     /// instantiated ParmVarDecl for 'x'.
-    llvm::DenseMap<const VarDecl *, VarDecl *> LocalDecls;
+    llvm::DenseMap<const Decl *, Decl *> LocalDecls;
 
     /// \brief The outer scope, in which contains local variable
     /// definitions from some other instantiation (that is not
@@ -2173,20 +2173,24 @@
       SemaRef.CurrentInstantiationScope = Outer;
     }
 
-    VarDecl *getInstantiationOf(const VarDecl *Var) {
-      VarDecl *Result = LocalDecls[Var];
-      assert(Result && "Variable was not instantiated in this scope!");
+    Decl *getInstantiationOf(const Decl *D) {
+      Decl *Result = LocalDecls[D];
+      assert(Result && "declaration was not instantiated in this scope!");
       return Result;
     }
 
-    ParmVarDecl *getInstantiationOf(const ParmVarDecl *Var) {
-      return cast<ParmVarDecl>(getInstantiationOf(cast<VarDecl>(Var)));
+    VarDecl *getInstantiationOf(const VarDecl *Var) {
+      return cast<VarDecl>(getInstantiationOf(cast<Decl>(Var)));
     }
 
-    void InstantiatedLocal(const VarDecl *Var, VarDecl *VarInst) {
-      VarDecl *&Stored = LocalDecls[Var];
-      assert(!Stored && "Already instantiated this local variable");
-      Stored = VarInst;
+    ParmVarDecl *getInstantiationOf(const ParmVarDecl *Var) {
+      return cast<ParmVarDecl>(getInstantiationOf(cast<Decl>(Var)));
+    }
+
+    void InstantiatedLocal(const Decl *D, Decl *Inst) {
+      Decl *&Stored = LocalDecls[D];
+      assert(!Stored && "Already instantiated this local");
+      Stored = Inst;
     }
   };
 
@@ -2246,6 +2250,9 @@
                                      FunctionDecl *Function);
   void InstantiateVariableDefinition(VarDecl *Var);
 
+  NamedDecl *
+  InstantiateDeclRef(NamedDecl *D, const TemplateArgumentList &TemplateArgs);
+  
   // Simple function for cloning expressions.
   template<typename T> 
   OwningExprResult Clone(T *E) {