[cfe-commits] r143615 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaAccess.cpp lib/Sema/SemaCodeComplete.cpp

Douglas Gregor dgregor at apple.com
Thu Nov 3 09:51:37 PDT 2011


Author: dgregor
Date: Thu Nov  3 11:51:37 2011
New Revision: 143615

URL: http://llvm.org/viewvc/llvm-project?rev=143615&view=rev
Log:
Refactor Sema::IsSimplyAccessible slightly, to work on a DeclContext rather than a class

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=143615&r1=143614&r2=143615&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Nov  3 11:51:37 2011
@@ -3754,7 +3754,7 @@
                                     bool ForceCheck = false,
                                     bool ForceUnprivileged = false);
   void CheckLookupAccess(const LookupResult &R);
-  bool IsSimplyAccessible(NamedDecl *decl, CXXRecordDecl *Class);
+  bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
 
   void HandleDependentAccessCheck(const DependentDiagnostic &DD,
                          const MultiLevelTemplateArgumentList &TemplateArgs);

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=143615&r1=143614&r2=143615&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Thu Nov  3 11:51:37 2011
@@ -1651,19 +1651,24 @@
 /// \param Decl the declaration to check if it can be accessed
 /// \param Class the class/context from which to start the search
 /// \return true if the Decl is accessible from the Class, false otherwise.
-bool Sema::IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *Class) {
-  if (!Class || !Decl->isCXXClassMember())
-    return true;
+bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) {
+  if (CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(Ctx)) {
+    if (!Class || !Decl->isCXXClassMember())
+      return true;
 
-  QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal();
-  AccessTarget Entity(Context, AccessedEntity::Member, Class,
-                      DeclAccessPair::make(Decl, Decl->getAccess()),
-                      qType);
-  if (Entity.getAccess() == AS_public)
-    return true;
+    QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal();
+    AccessTarget Entity(Context, AccessedEntity::Member, Class,
+                        DeclAccessPair::make(Decl, Decl->getAccess()),
+                        qType);
+    if (Entity.getAccess() == AS_public)
+      return true;
 
-  EffectiveContext EC(CurContext);
-  return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible;
+    EffectiveContext EC(CurContext);
+    return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible;
+  }
+  
+  // FIXME: Check access for Objective-C ivars.
+  return true;
 }
 
 void Sema::ActOnStartSuppressingAccessChecks() {

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=143615&r1=143614&r2=143615&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Nov  3 11:51:37 2011
@@ -1189,11 +1189,9 @@
     virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
                            bool InBaseClass) {
       bool Accessible = true;
-      if (Ctx) {
-        if (CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(Ctx))
-          Accessible = Results.getSema().IsSimplyAccessible(ND, Class);
-        // FIXME: ObjC access checks are missing.
-      }
+      if (Ctx)
+        Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx);
+      
       ResultBuilder::Result Result(ND, 0, false, Accessible);
       Results.AddResult(Result, CurContext, Hiding, InBaseClass);
     }





More information about the cfe-commits mailing list