[cfe-commits] r74279 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/Sema/SemaLookup.cpp

Anders Carlsson andersca at mac.com
Thu Jun 25 23:29:29 PDT 2009


Author: andersca
Date: Fri Jun 26 01:29:23 2009
New Revision: 74279

URL: http://llvm.org/viewvc/llvm-project?rev=74279&view=rev
Log:
Add NamedDecl::getUnderlyingDecl that can see through UsingDecl and ObjCCompatibleAliasDecl.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Jun 26 01:29:23 2009
@@ -106,6 +106,13 @@
   /// \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;
   }

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Jun 26 01:29:23 2009
@@ -297,6 +297,19 @@
   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
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Jun 26 01:29:23 2009
@@ -139,20 +139,14 @@
         // 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 @@
       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 @@
 
 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 @@
     }
   } 
 
-  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 @@
     }
   }
 
-  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;





More information about the cfe-commits mailing list