[cfe-commits] r67725 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Wed Mar 25 18:19:02 PDT 2009


Author: andersca
Date: Wed Mar 25 20:19:02 2009
New Revision: 67725

URL: http://llvm.org/viewvc/llvm-project?rev=67725&view=rev
Log:
Factor the member access specifier setting code into its own function. No intended functionality change.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Mar 25 20:19:02 2009
@@ -1616,6 +1616,13 @@
                                  FunctionDecl::StorageClass& SC);
   DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
 
+  /// SetMemberAccessSpecifier - Set the access specifier of a member.
+  /// Returns true on error (when the previous member decl access specifier
+  /// is different from the new member decl access specifier).
+  bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 
+                                NamedDecl *PrevMemberDecl,
+                                AccessSpecifier LexicalAS);
+  
   //===--------------------------------------------------------------------===//
   // C++ Derived Classes
   //

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 25 20:19:02 2009
@@ -3083,21 +3083,6 @@
   return NewTD;
 }
 
-static const char *getAccessName(AccessSpecifier AS) {
-  switch (AS) {
-    default:
-    case AS_none:
-      assert("Invalid access specifier!");
-      return 0;
-    case AS_public:
-      return "public";
-    case AS_private:
-      return "private";
-    case AS_protected:
-      return "protected";
-  }
-}
-
 /// ActOnTag - This is invoked when we see 'struct foo' or 'struct {'.  In the
 /// former case, Name will be non-null.  In the later case, Name will be null.
 /// TagSpec indicates what kind of tag this is. TK indicates whether this is a
@@ -3399,18 +3384,8 @@
   // lexical context will be different from the semantic context.
   New->setLexicalDeclContext(CurContext);
 
-  if (PrevDecl) {
-    // C++ [class.access.spec]p3: When a member is redeclared its access
-    // specifier must be same as its initial declaration.
-    if (AS != AS_none && AS != PrevDecl->getAccess()) {
-      Diag(Loc, diag::err_class_redeclared_with_different_access) 
-        << New << getAccessName(AS);
-      Diag(PrevDecl->getLocation(), diag::note_previous_access_declaration)
-        << PrevDecl << getAccessName(PrevDecl->getAccess());
-    } else 
-      New->setAccess(PrevDecl->getAccess());
-  } else
-    New->setAccess(AS);
+  // Set the access specifier.
+  SetMemberAccessSpecifier(New, PrevDecl, AS);
 
   if (TK == TK_Definition)
     New->startDefinition();

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Mar 25 20:19:02 2009
@@ -2529,3 +2529,43 @@
   }
   Fn->setDeleted();
 }
+
+static const char *getAccessName(AccessSpecifier AS) {
+  switch (AS) {
+    default:
+    case AS_none:
+      assert("Invalid access specifier!");
+      return 0;
+    case AS_public:
+      return "public";
+    case AS_private:
+      return "private";
+    case AS_protected:
+      return "protected";
+  }
+}
+
+bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, 
+                                    NamedDecl *PrevMemberDecl,
+                                    AccessSpecifier LexicalAS) {
+  if (!PrevMemberDecl) {
+    // Use the lexical access specifier.
+    MemberDecl->setAccess(LexicalAS);
+    return false;
+  }
+  
+  // C++ [class.access.spec]p3: When a member is redeclared its access
+  // specifier must be same as its initial declaration.
+  if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
+    Diag(MemberDecl->getLocation(), 
+         diag::err_class_redeclared_with_different_access) 
+      << MemberDecl << getAccessName(LexicalAS);
+    Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration)
+      << PrevMemberDecl << getAccessName(PrevMemberDecl->getAccess());
+    return true;
+  }
+  
+  MemberDecl->setAccess(PrevMemberDecl->getAccess());
+  return false;
+}
+





More information about the cfe-commits mailing list