]> granicus.if.org Git - clang/commitdiff
Add NamedDecl::getUnderlyingDecl that can see through UsingDecl and ObjCCompatibleAli...
authorAnders Carlsson <andersca@mac.com>
Fri, 26 Jun 2009 06:29:23 +0000 (06:29 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 26 Jun 2009 06:29:23 +0000 (06:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74279 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Sema/SemaLookup.cpp

index ed2c790af6885335400b10c252bc77b7137353fb..3de01f3baeb5deaac80cddc42f3d3c17cf81265e 100644 (file)
@@ -106,6 +106,13 @@ public:
   /// \brief Determine whether this declaration has linkage.
   bool hasLinkage() const;
 
+  /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
+  /// the underlying named decl.
+  NamedDecl *getUnderlyingDecl();
+  const NamedDecl *getUnderlyingDecl() const {
+    return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
+  }
+  
   static bool classof(const Decl *D) {
     return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
   }
index 4fbf2f6f48eb0cbbc5220ee90adac727a4e78166..5382ab52ab5b08740ce497c25165b804b31a51b5 100644 (file)
@@ -297,6 +297,19 @@ bool NamedDecl::hasLinkage() const {
   return false;
 }
 
+NamedDecl *NamedDecl::getUnderlyingDecl() {
+  NamedDecl *ND = this;
+  while (true) {
+    if (UsingDecl *UD = dyn_cast<UsingDecl>(ND))
+      ND = UD->getTargetDecl();
+    else if (ObjCCompatibleAliasDecl *AD
+              = dyn_cast<ObjCCompatibleAliasDecl>(ND))
+      return AD->getClassInterface();
+    else
+      return ND;
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // VarDecl Implementation
 //===----------------------------------------------------------------------===//
index d76761c696351f199468364a5b83181e5d9c4bad..cc9e783f61662af8d1504ab5429d0877ba1f834d 100644 (file)
@@ -139,20 +139,14 @@ MaybeConstructOverloadSet(ASTContext &Context,
         // nothing to leak.
         Ovl = OverloadedFunctionDecl::Create(Context, (*I)->getDeclContext(),
                                              (*I)->getDeclName());
-        NamedDecl *ND = (*I);
-        if (UsingDecl *UD = dyn_cast<UsingDecl>(ND))
-          ND = UD->getTargetDecl();
-
+        NamedDecl *ND = (*I)->getUnderlyingDecl();
         if (isa<FunctionDecl>(ND))
           Ovl->addOverload(cast<FunctionDecl>(ND));
         else
           Ovl->addOverload(cast<FunctionTemplateDecl>(ND));
       }
 
-      NamedDecl *ND = (*Last);
-      if (UsingDecl *UD = dyn_cast<UsingDecl>(ND))
-        ND = UD->getTargetDecl();
-      
+      NamedDecl *ND = (*Last)->getUnderlyingDecl();
       if (isa<FunctionDecl>(ND))
         Ovl->addOverload(cast<FunctionDecl>(ND));
       else
@@ -219,9 +213,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) {
       break;
 
     case LResult::Found: {
-      NamedDecl *ND = I->getAsDecl();
-      if (UsingDecl *UD = dyn_cast<UsingDecl>(ND))
-        ND = UD->getTargetDecl();
+      NamedDecl *ND = I->getAsDecl()->getUnderlyingDecl();
         
       if (TagDecl *TD = dyn_cast<TagDecl>(ND)) {
         TagFound = Context.getCanonicalDecl(TD);
@@ -333,11 +325,8 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
 
 Sema::LookupResult
 Sema::LookupResult::CreateLookupResult(ASTContext &Context, NamedDecl *D) {
-  if (ObjCCompatibleAliasDecl *Alias 
-        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
-    D = Alias->getClassInterface();
-  if (UsingDecl *UD = dyn_cast_or_null<UsingDecl>(D))
-    D = UD->getTargetDecl();
+  if (D)
+    D = D->getUnderlyingDecl();
   
   LookupResult Result;
   Result.StoredKind = (D && isa<OverloadedFunctionDecl>(D))?
@@ -367,12 +356,9 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context,
     }
   } 
 
-  Decl *D = *F;
-  if (ObjCCompatibleAliasDecl *Alias 
-        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
-    D = Alias->getClassInterface();
-  if (UsingDecl *UD = dyn_cast_or_null<UsingDecl>(D))
-    D = UD->getTargetDecl();
+  NamedDecl *D = *F;
+  if (D)
+    D = D->getUnderlyingDecl();
 
   Result.StoredKind = SingleDecl;
   Result.First = reinterpret_cast<uintptr_t>(D);
@@ -398,13 +384,10 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context,
     }
   }
 
-  Decl *D = *F;
-  if (ObjCCompatibleAliasDecl *Alias 
-        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
-    D = Alias->getClassInterface();
-  if (UsingDecl *UD = dyn_cast_or_null<UsingDecl>(D))
-    D = UD->getTargetDecl();
-
+  NamedDecl *D = *F;
+  if (D)
+    D = D->getUnderlyingDecl();
+  
   Result.StoredKind = SingleDecl;
   Result.First = reinterpret_cast<uintptr_t>(D);
   Result.Last = 0;