Commit abadf320 authored by Roberto Raggi's avatar Roberto Raggi

Handle symbol visibility.

parent 849a52ae
...@@ -66,20 +66,28 @@ Bind::Bind(TranslationUnit *unit) ...@@ -66,20 +66,28 @@ Bind::Bind(TranslationUnit *unit)
_scope(0), _scope(0),
_expression(0), _expression(0),
_name(0), _name(0),
_declaratorId(0) _declaratorId(0),
_visibility(Symbol::Public),
_methodKey(Function::NormalMethod)
{ {
} }
Scope *Bind::currentScope() const Scope *Bind::switchScope(Scope *scope)
{ {
return _scope; std::swap(_scope, scope);
return scope;
} }
Scope *Bind::switchScope(Scope *scope) int Bind::switchVisibility(int visibility)
{
std::swap(_visibility, visibility);
return visibility;
}
int Bind::switchMethodKey(int methodKey)
{ {
Scope *previousScope = _scope; std::swap(_methodKey, methodKey);
_scope = scope; return methodKey;
return previousScope;
} }
void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace) void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
...@@ -1502,6 +1510,17 @@ bool Bind::visit(AccessDeclarationAST *ast) ...@@ -1502,6 +1510,17 @@ bool Bind::visit(AccessDeclarationAST *ast)
// unsigned access_specifier_token = ast->access_specifier_token; // unsigned access_specifier_token = ast->access_specifier_token;
// unsigned slots_token = ast->slots_token; // unsigned slots_token = ast->slots_token;
// unsigned colon_token = ast->colon_token; // unsigned colon_token = ast->colon_token;
const int accessSpecifier = tokenKind(ast->access_specifier_token);
_visibility = visibilityForAccessSpecifier(accessSpecifier);
if (ast->slots_token)
_methodKey = Function::SlotMethod;
else if (accessSpecifier == T_Q_SIGNALS)
_methodKey = Function::SignalMethod;
else
_methodKey = Function::NormalMethod;
return false; return false;
} }
...@@ -2170,6 +2189,8 @@ bool Bind::visit(ClassSpecifierAST *ast) ...@@ -2170,6 +2189,8 @@ bool Bind::visit(ClassSpecifierAST *ast)
_type.setType(klass); _type.setType(klass);
Scope *previousScope = switchScope(klass); Scope *previousScope = switchScope(klass);
const int previousVisibility = switchVisibility(Symbol::Public);
const int previousMethodKey = switchMethodKey(Function::NormalMethod);
for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) { for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
this->baseSpecifier(it->value, ast->colon_token, klass); this->baseSpecifier(it->value, ast->colon_token, klass);
...@@ -2178,7 +2199,11 @@ bool Bind::visit(ClassSpecifierAST *ast) ...@@ -2178,7 +2199,11 @@ bool Bind::visit(ClassSpecifierAST *ast)
for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) { for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) {
this->declaration(it->value); this->declaration(it->value);
} }
(void) switchMethodKey(previousMethodKey);
(void) switchVisibility(previousVisibility);
(void) switchScope(previousScope); (void) switchScope(previousScope);
ast->symbol = klass; ast->symbol = klass;
return false; return false;
} }
......
...@@ -79,8 +79,9 @@ protected: ...@@ -79,8 +79,9 @@ protected:
FullySpecifiedType coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init); FullySpecifiedType coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init);
FullySpecifiedType postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init); FullySpecifiedType postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init);
Scope *currentScope() const;
Scope *switchScope(Scope *scope); Scope *switchScope(Scope *scope);
int switchVisibility(int visibility);
int switchMethodKey(int methodKey);
const Name *objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg); const Name *objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg);
void attribute(AttributeAST *ast); void attribute(AttributeAST *ast);
...@@ -278,6 +279,8 @@ private: ...@@ -278,6 +279,8 @@ private:
const Name *_name; const Name *_name;
FullySpecifiedType _type; FullySpecifiedType _type;
DeclaratorIdAST **_declaratorId; DeclaratorIdAST **_declaratorId;
int _visibility;
int _methodKey;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment