[cfe-commits] r60708 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaTemplate.cpp

Douglas Gregor dgregor at apple.com
Mon Dec 8 10:40:44 PST 2008


Author: dgregor
Date: Mon Dec  8 12:40:42 2008
New Revision: 60708

URL: http://llvm.org/viewvc/llvm-project?rev=60708&view=rev
Log:
Move Sema::isTemplateParameterDecl to Decl::isTemplateParameter, where it belongs

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Mon Dec  8 12:40:42 2008
@@ -211,6 +211,10 @@
   static bool CollectingStats(bool Enable = false);
   static void PrintStats();
     
+  /// isTemplateParameter - Determines whether this declartion is a
+  /// template parameter.
+  bool isTemplateParameter() const;
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *) { return true; }
   static DeclContext *castToDeclContext(const Decl *);
@@ -388,6 +392,11 @@
   static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; }
 };
 
+inline bool Decl::isTemplateParameter() const {
+  return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm;
+}
+
+
 } // end clang.
 
 namespace llvm {

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Dec  8 12:40:42 2008
@@ -995,7 +995,6 @@
   //===--------------------------------------------------------------------===//
   // C++ Templates [C++ 14]
   //
-  bool isTemplateParameterDecl(Decl *D);
   bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
   virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, 
 				     SourceLocation KeyLoc,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec  8 12:40:42 2008
@@ -868,7 +868,7 @@
     }
   }
 
-  if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+  if (PrevDecl && PrevDecl->isTemplateParameter()) {
     // Maybe we will complain about the shadowed template parameter.
     InvalidDecl = InvalidDecl 
       || DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl);
@@ -2035,7 +2035,7 @@
   // among each other.  Here they can only shadow globals, which is ok.
   IdentifierInfo *II = D.getIdentifier();
   if (Decl *PrevDecl = LookupDecl(II, Decl::IDNS_Ordinary, S)) {
-    if (isTemplateParameterDecl(PrevDecl)) {
+    if (PrevDecl->isTemplateParameter()) {
       // Maybe we will complain about the shadowed template parameter.
       DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl);
       // Just pretend that we didn't see the previous declaration.
@@ -2299,7 +2299,7 @@
     PrevDecl = dyn_cast_or_null<ScopedDecl>(LookupDecl(Name, Decl::IDNS_Tag,S));
   }
 
-  if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+  if (PrevDecl && PrevDecl->isTemplateParameter()) {
     // Maybe we will complain about the shadowed template parameter.
     DiagnoseTemplateParameterShadow(NameLoc, PrevDecl);
     // Just pretend that we didn't see the previous declaration.
@@ -2442,7 +2442,7 @@
     PrevDecl = dyn_cast_or_null<ScopedDecl>(LookupDecl(Name, Decl::IDNS_Tag,S));
   }
   
-  if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+  if (PrevDecl && PrevDecl->isTemplateParameter()) {
     // Maybe we will complain about the shadowed template parameter.
     DiagnoseTemplateParameterShadow(NameLoc, PrevDecl);
     // Just pretend that we didn't see the previous declaration.
@@ -2959,7 +2959,7 @@
   // Verify that there isn't already something declared with this name in this
   // scope.
   Decl *PrevDecl = LookupDecl(Id, Decl::IDNS_Ordinary, S);
-  if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+  if (PrevDecl && PrevDecl->isTemplateParameter()) {
     // Maybe we will complain about the shadowed template parameter.
     DiagnoseTemplateParameterShadow(IdLoc, PrevDecl);
     // Just pretend that we didn't see the previous declaration.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Dec  8 12:40:42 2008
@@ -66,7 +66,7 @@
   
   // Check for another declaration kind with the same name.
   Decl *PrevDecl = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope);
-  if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+  if (PrevDecl && PrevDecl->isTemplateParameter()) {
     // Maybe we will complain about the shadowed template parameter.
     DiagnoseTemplateParameterShadow(ClassLoc, PrevDecl);
     // Just pretend that we didn't see the previous declaration.
@@ -826,7 +826,7 @@
   for (unsigned i = 0; i != NumElts; ++i) {
     // Check for another declaration kind with the same name.
     Decl *PrevDecl = LookupDecl(IdentList[i], Decl::IDNS_Ordinary, TUScope);
-    if (PrevDecl && isTemplateParameterDecl(PrevDecl)) {
+    if (PrevDecl && PrevDecl->isTemplateParameter()) {
       // Maybe we will complain about the shadowed template parameter.
       DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl);
       // Just pretend that we didn't see the previous declaration.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec  8 12:40:42 2008
@@ -18,18 +18,12 @@
 
 using namespace clang;
 
-/// isTemplateParameterDecl - Determines whether the given declaration
-/// 'D' names a template parameter.
-bool Sema::isTemplateParameterDecl(Decl *D) {
-  return isa<TemplateTypeParmDecl>(D) || isa<NonTypeTemplateParmDecl>(D);
-}
-
 /// DiagnoseTemplateParameterShadow - Produce a diagnostic complaining
 /// that the template parameter 'PrevDecl' is being shadowed by a new
 /// declaration at location Loc. Returns true to indicate that this is
 /// an error, and false otherwise.
 bool Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) {
-  assert(isTemplateParameterDecl(PrevDecl) && "Not a template parameter");
+  assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
 
   // Microsoft Visual C++ permits template parameters to be shadowed.
   if (getLangOptions().Microsoft)
@@ -63,7 +57,7 @@
 
   if (ParamName) {
     Decl *PrevDecl = LookupDecl(ParamName, Decl::IDNS_Tag, S);
-    if (PrevDecl && isTemplateParameterDecl(PrevDecl))
+    if (PrevDecl && PrevDecl->isTemplateParameter())
       Invalid = Invalid || DiagnoseTemplateParameterShadow(ParamNameLoc,
 							   PrevDecl);
   }
@@ -97,7 +91,7 @@
   IdentifierInfo *ParamName = D.getIdentifier();
   if (ParamName) {
     Decl *PrevDecl = LookupDecl(ParamName, Decl::IDNS_Tag, S);
-    if (PrevDecl && isTemplateParameterDecl(PrevDecl))
+    if (PrevDecl && PrevDecl->isTemplateParameter())
       Invalid = Invalid || DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
 							   PrevDecl);
   }





More information about the cfe-commits mailing list