]> granicus.if.org Git - clang/commitdiff
Move Sema::isTemplateParameterDecl to Decl::isTemplateParameter, where it belongs
authorDouglas Gregor <dgregor@apple.com>
Mon, 8 Dec 2008 18:40:42 +0000 (18:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 8 Dec 2008 18:40:42 +0000 (18:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60708 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaTemplate.cpp

index 6d61da4698372dc1d5174ba6b6e58cc3a0a444cf..55919da54e94c41fc7aca64490d21f6ad13a7100 100644 (file)
@@ -211,6 +211,10 @@ public:
   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 @@ template<> struct DeclContext::KindTrait<DeclContext> {
   static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; }
 };
 
+inline bool Decl::isTemplateParameter() const {
+  return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm;
+}
+
+
 } // end clang.
 
 namespace llvm {
index ef99aaaa46c6bdbfd0e61d418ce1605c1e615cda..4a8f83084dd6d83ea808980e1d715d5a7971b0ea 100644 (file)
@@ -995,7 +995,6 @@ public:
   //===--------------------------------------------------------------------===//
   // C++ Templates [C++ 14]
   //
-  bool isTemplateParameterDecl(Decl *D);
   bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
   virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, 
                                     SourceLocation KeyLoc,
index b6b1f4c44658b2bc607c049517eedaa1932ae6f8..41587c5aee65bc43f69c84d451018bf8896c8bed 100644 (file)
@@ -868,7 +868,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
     }
   }
 
-  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 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
   // 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 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
     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 @@ Sema::DeclTy *Sema::ActOnTagStruct(Scope *S, TagDecl::TagKind Kind, TagKind TK,
     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 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
   // 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.
index d7b71211d49d9ba897f8e71ccca1da17e193072f..7a93b453f07ccb5083429bc61f387d50c947a225 100644 (file)
@@ -66,7 +66,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
   
   // 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 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
   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.
index 092c9d2236a5b881cf2369c680da4c1b6c934b8c..2dcb9fe3361c4d1bdc34298332017a9d2f20eb83 100644 (file)
 
 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 @@ Sema::DeclTy *Sema::ActOnTypeParameter(Scope *S, bool Typename,
 
   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 @@ Sema::DeclTy *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D) {
   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);
   }