From 84920f53b83adbfa9811a7c293387c26829d4481 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Fri, 13 Aug 2010 12:24:29 +0200
Subject: [PATCH] Update the member's visibility.

---
 src/shared/cplusplus/Bind.cpp | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/shared/cplusplus/Bind.cpp b/src/shared/cplusplus/Bind.cpp
index cbb492f32b7..2ad1c6fbdab 100644
--- a/src/shared/cplusplus/Bind.cpp
+++ b/src/shared/cplusplus/Bind.cpp
@@ -2380,10 +2380,22 @@ bool Bind::visit(ClassSpecifierAST *ast)
     klass->setEndOffset(tokenAt(ast->lastToken() - 1).end());
     _scope->addMember(klass);
 
+    if (_scope->isClass())
+        klass->setVisibility(_visibility);
+
+    // set the class key
+    unsigned classKey = tokenKind(ast->classkey_token);
+    if (classKey == T_CLASS)
+        klass->setClassKey(Class::ClassKey);
+    else if (classKey == T_STRUCT)
+        klass->setClassKey(Class::StructKey);
+    else if (classKey == T_UNION)
+        klass->setClassKey(Class::UnionKey);
+
     _type.setType(klass);
 
     Scope *previousScope = switchScope(klass);
-    const int previousVisibility = switchVisibility(Symbol::Public);
+    const int previousVisibility = switchVisibility(visibilityForClassKey(classKey));
     const int previousMethodKey = switchMethodKey(Function::NormalMethod);
 
     for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
@@ -2431,6 +2443,9 @@ bool Bind::visit(EnumSpecifierAST *ast)
     ast->symbol = e;
     _scope->addMember(e);
 
+    if (_scope->isClass())
+        e->setVisibility(_visibility);
+
     Scope *previousScope = switchScope(e);
     for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
         this->enumerator(it->value, e);
@@ -2594,3 +2609,16 @@ int Bind::visibilityForAccessSpecifier(int tokenKind)
         return Symbol::Public;
     }
 }
+
+int Bind::visibilityForClassKey(int tokenKind)
+{
+    switch (tokenKind) {
+    case T_CLASS:
+        return Symbol::Private;
+    case T_STRUCT:
+    case T_UNION:
+        return Symbol::Public;
+    default:
+        return Symbol::Public;
+    }
+}
-- 
GitLab