[cfe-commits] r90848 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CGBlocks.cpp lib/Frontend/PCHReaderStmt.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/TreeTransform.h

John McCall rjmccall at apple.com
Tue Dec 8 01:08:17 PST 2009


Author: rjmccall
Date: Tue Dec  8 03:08:17 2009
New Revision: 90848

URL: http://llvm.org/viewvc/llvm-project?rev=90848&view=rev
Log:
DeclRefExpr stores a ValueDecl internally.

Template instantiation can re-use DeclRefExprs.


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Dec  8 03:08:17 2009
@@ -389,7 +389,7 @@
   // indicate whether (1) the declaration's name was explicitly qualified and
   // (2) the declaration's name was followed by an explicit template 
   // argument list.
-  llvm::PointerIntPair<NamedDecl *, 2> DecoratedD;
+  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
   
   // Loc - The location of the declaration name itself.
   SourceLocation Loc;
@@ -427,7 +427,7 @@
   }
   
   DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
-              NamedDecl *D, SourceLocation NameLoc,
+              ValueDecl *D, SourceLocation NameLoc,
               const TemplateArgumentListInfo *TemplateArgs,
               QualType T);
   
@@ -436,13 +436,13 @@
   /// declaration reference expression.
   void computeDependence();
 
-  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
+  DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) :
     Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) {
     computeDependence();
   }
 
 public:
-  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
+  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
     Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
     computeDependence();
   }
@@ -454,14 +454,14 @@
   static DeclRefExpr *Create(ASTContext &Context,
                              NestedNameSpecifier *Qualifier,
                              SourceRange QualifierRange,
-                             NamedDecl *D,
+                             ValueDecl *D,
                              SourceLocation NameLoc,
                              QualType T,
                              const TemplateArgumentListInfo *TemplateArgs = 0);
   
-  NamedDecl *getDecl() { return DecoratedD.getPointer(); }
-  const NamedDecl *getDecl() const { return DecoratedD.getPointer(); }
-  void setDecl(NamedDecl *NewD) { DecoratedD.setPointer(NewD); }
+  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
+  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
+  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
 
   SourceLocation getLocation() const { return Loc; }
   void setLocation(SourceLocation L) { Loc = L; }

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Dec  8 03:08:17 2009
@@ -110,7 +110,7 @@
 
 DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 
                          SourceRange QualifierRange,
-                         NamedDecl *D, SourceLocation NameLoc,
+                         ValueDecl *D, SourceLocation NameLoc,
                          const TemplateArgumentListInfo *TemplateArgs,
                          QualType T)
   : Expr(DeclRefExprClass, T, false, false),
@@ -133,7 +133,7 @@
 DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
                                  NestedNameSpecifier *Qualifier,
                                  SourceRange QualifierRange,
-                                 NamedDecl *D,
+                                 ValueDecl *D,
                                  SourceLocation NameLoc,
                                  QualType T,
                                  const TemplateArgumentListInfo *TemplateArgs) {

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Dec  8 03:08:17 2009
@@ -296,7 +296,7 @@
             ++helpersize;
             continue;
           } else
-            E = new (getContext()) DeclRefExpr (cast<NamedDecl>(VD),
+            E = new (getContext()) DeclRefExpr (VD,
                                                 VD->getType(), 
                                                 SourceLocation());
         }

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Tue Dec  8 03:08:17 2009
@@ -349,7 +349,7 @@
 
 unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
   VisitExpr(E);
-  E->setDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
+  E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
   E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
   // FIXME: read qualifier
   // FIXME: read explicit template arguments

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Dec  8 03:08:17 2009
@@ -1448,7 +1448,7 @@
                                               bool isAddressOfOperand,
                                 const TemplateArgumentListInfo *TemplateArgs);
   
-  OwningExprResult BuildDeclRefExpr(NamedDecl *D, QualType Ty,
+  OwningExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
                                     SourceLocation Loc,
                                     const CXXScopeSpec *SS = 0);
   VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec  8 03:08:17 2009
@@ -415,7 +415,7 @@
 
 /// BuildDeclRefExpr - Build a DeclRefExpr.
 Sema::OwningExprResult
-Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
+Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, SourceLocation Loc,
                        const CXXScopeSpec *SS) {
   if (Context.getCanonicalType(Ty) == Context.UndeducedAutoTy) {
     Diag(Loc,

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Dec  8 03:08:17 2009
@@ -782,25 +782,8 @@
     // FindInstantiatedDecl will find it in the local instantiation scope.
   }
 
-  NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D, TemplateArgs);
-  if (!InstD)
-    return SemaRef.ExprError();
-
-  assert(!isa<UsingDecl>(InstD) && "decl ref instantiated to UsingDecl");
-
-  CXXScopeSpec SS;
-  NestedNameSpecifier *Qualifier = 0;
-  if (E->getQualifier()) {
-    Qualifier = TransformNestedNameSpecifier(E->getQualifier(),
-                                             E->getQualifierRange());
-    if (!Qualifier)
-      return SemaRef.ExprError();
-    
-    SS.setScopeRep(Qualifier);
-    SS.setRange(E->getQualifierRange());
-  }
-  
-  return SemaRef.BuildDeclarationNameExpr(SS, E->getLocation(), InstD);
+  return TreeTransform<TemplateInstantiator>::
+    TransformDeclRefExpr(E, isAddressOfOperand);
 }
 
 Sema::OwningExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=90848&r1=90847&r2=90848&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Dec  8 03:08:17 2009
@@ -830,15 +830,15 @@
   /// Subclasses may override this routine to provide different behavior.
   OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
                                       SourceRange QualifierRange,
-                                      NamedDecl *ND, SourceLocation Loc,
-                                      bool isAddressOfOperand) {
+                                      ValueDecl *VD, SourceLocation Loc,
+                                      TemplateArgumentListInfo *TemplateArgs) {
     CXXScopeSpec SS;
     SS.setScopeRep(Qualifier);
     SS.setRange(QualifierRange);
-    return getSema().BuildDeclarationNameExpr(Loc, ND,
-                                              /*FIXME:*/false,
-                                              &SS,
-                                              isAddressOfOperand);
+
+    // FIXME: loses template args.
+    
+    return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
   }
 
   /// \brief Build a new expression in parentheses.
@@ -3484,31 +3484,39 @@
     if (!Qualifier)
       return SemaRef.ExprError();
   }
-  
-  NamedDecl *ND
-    = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
+
+  ValueDecl *ND
+    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
   if (!ND)
     return SemaRef.ExprError();
 
   if (!getDerived().AlwaysRebuild() && 
       Qualifier == E->getQualifier() &&
       ND == E->getDecl() &&
-      !E->hasExplicitTemplateArgumentList())
-    return SemaRef.Owned(E->Retain());
+      !E->hasExplicitTemplateArgumentList()) {
 
-  // FIXME: We're losing the explicit template arguments in this transformation.
+    // Mark it referenced in the new context regardless.
+    // FIXME: this is a bit instantiation-specific.
+    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
 
-  llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
-  for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
-    if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
-                                               TransArgs[I]))
-      return SemaRef.ExprError();
+    return SemaRef.Owned(E->Retain());
   }
-  
-  // FIXME: Pass the qualifier/qualifier range along.
+
+  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
+  if (E->hasExplicitTemplateArgumentList()) {
+    TemplateArgs = &TransArgs;
+    TransArgs.setLAngleLoc(E->getLAngleLoc());
+    TransArgs.setRAngleLoc(E->getRAngleLoc());
+    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
+      TemplateArgumentLoc Loc;
+      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
+        return SemaRef.ExprError();
+      TransArgs.addArgument(Loc);
+    }
+  }
+
   return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
-                                         ND, E->getLocation(),
-                                         isAddressOfOperand);
+                                         ND, E->getLocation(), TemplateArgs);
 }
 
 template<typename Derived>





More information about the cfe-commits mailing list