Commit 6accf66c authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

rename MemberAccessibility to SymbolAccessibility and move its declaration

2007-08-30  Juerg Billeter  <j@bitron.ch>

	* vala/valamemberaccessibility.vala: rename MemberAccessibility to
	  SymbolAccessibility and move its declaration to vala/valasymbol.vala
	* vala/parser.y: store accessibility modifier for properties and follow
	  the renames caused by the accessibility releated refactoring, cast
	  the Struct allocated in struct_declaration to silence gcc
	* vala/Makefile.am: remove valamemberaccessibility.* files
	* vala/valasymbol.vala: add access property found in serveral
	  sub-classes and add is_internal_symbol () method, which considers
	  parent symbols to determinate if a symbol belongs to internal API
	* gobject/*, vala/*, vapigen/valagidlparser.vala:
	  move the access property/field found in several Symbol derived
	  classes to the Symbol class where it belongs and rename the
	  MemberAccessibility enumeration to SymbolAccessibility

	* vala/valaformalparameter.vala, vala/valanamespace.vala: set access
	  to public on initialization, as there is no accessibility modifier
	* gobject/valacodegenerator.vala: do not add internal symbols to
	  header_type_member_declarations
	* vala/valasemanticanalyzer.vala: do not add HEADER_SHALLOW symbol
	  dependencies for internal symbols
	* gobject/valacodegeneratormethod.vala: consider all anchestors,
	  not just the parent for visibility

	patch by Mathias Hasselmann, fixes bug 471475

svn path=/trunk/; revision=546
parent dafce8e1
/* valamemberaccessibility.vala
*
* Copyright (C) 2006 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
public enum Vala.MemberAccessibility {
PRIVATE,
INTERNAL,
PROTECTED,
PUBLIC
}
......@@ -37,14 +37,6 @@ public class Vala.Method : Member, Invokable {
public Block body { get; set; }
/**
* Specifies the accessibility of this method. Public accessibility
* doesn't limit access. Default accessibility limits access to this
* program or library. Private accessibility limits access to instances
* of the contained type.
*/
public MemberAccessibility access;
/**
* Specifies whether this method may only be called with an instance of
* the contained type.
......
......@@ -56,6 +56,7 @@ public class Vala.Namespace : Symbol {
* @return newly created namespace
*/
public Namespace (construct string name, construct SourceReference source_reference = null) {
access = SymbolAccessibility.PUBLIC;
}
/**
......
......@@ -41,14 +41,6 @@ public class Vala.Property : Member, Lockable {
*/
public PropertyAccessor set_accessor { get; set; }
/**
* Specifies the accessibility of this property. Public accessibility
* doesn't limit access. Default accessibility limits access to this
* program or library. Private accessibility limits access to the parent
* class.
*/
public MemberAccessibility access { get; set; }
/**
* Represents the generated ´this' parameter in this property.
*/
......
......@@ -325,7 +325,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public override void visit_field (Field! f) {
f.accept_children (this);
if (f.access != MemberAccessibility.PRIVATE) {
if (!f.is_internal_symbol ()) {
if (f.type_reference.data_type != null) {
/* is null if it references a type parameter */
current_source_file.add_symbol_dependency (f.type_reference.data_type, SourceFileDependencyType.HEADER_SHALLOW);
......@@ -355,7 +355,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (m.return_type.data_type != null) {
/* is null if it is void or a reference to a type parameter */
current_source_file.add_symbol_dependency (m.return_type.data_type, SourceFileDependencyType.HEADER_SHALLOW);
if (!m.is_internal_symbol ()) {
current_source_file.add_symbol_dependency (m.return_type.data_type, SourceFileDependencyType.HEADER_SHALLOW);
}
current_source_file.add_symbol_dependency (m.return_type.data_type, SourceFileDependencyType.SOURCE);
}
m.accept_children (this);
......@@ -474,7 +477,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (!p.ellipsis) {
if (p.type_reference.data_type != null) {
/* is null if it references a type parameter */
current_source_file.add_symbol_dependency (p.type_reference.data_type, SourceFileDependencyType.HEADER_SHALLOW);
if (!p.is_internal_symbol ()) {
current_source_file.add_symbol_dependency (p.type_reference.data_type, SourceFileDependencyType.HEADER_SHALLOW);
}
current_source_file.add_symbol_dependency (p.type_reference.data_type, SourceFileDependencyType.SOURCE);
}
}
......@@ -547,7 +552,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (prop.type_reference.data_type != null) {
/* is null if it references a type parameter */
current_source_file.add_symbol_dependency (prop.type_reference.data_type, SourceFileDependencyType.HEADER_SHALLOW);
if (!prop.is_internal_symbol ()) {
current_source_file.add_symbol_dependency (prop.type_reference.data_type, SourceFileDependencyType.HEADER_SHALLOW);
}
current_source_file.add_symbol_dependency (prop.type_reference.data_type, SourceFileDependencyType.SOURCE);
}
......@@ -1282,7 +1289,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
var member = expr.symbol_reference;
MemberAccessibility access = MemberAccessibility.PUBLIC;
var access = SymbolAccessibility.PUBLIC;
bool instance = false;
if (member is Field) {
var f = (Field) member;
......@@ -1296,7 +1303,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
instance = true;
}
if (access == MemberAccessibility.PRIVATE) {
if (access == SymbolAccessibility.PRIVATE) {
var target_type = member.parent_symbol;
bool in_target_type = false;
......@@ -2540,7 +2547,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
var m = (Method) a.right.symbol_reference;
if (m.instance && m.access != MemberAccessibility.PRIVATE) {
if (m.instance && m.access != SymbolAccessibility.PRIVATE) {
/* TODO: generate wrapper function */
ma.error = true;
......
......@@ -32,12 +32,6 @@ public class Vala.Signal : Member, Invokable, Lockable {
*/
public TypeReference! return_type { get; set; }
/**
* Specifies the accessibility of the signal. Currently only public
* accessibility is supported for signals.
*/
public MemberAccessibility access { get; set; }
/**
* Specifies whether this signal has an emitter wrapper function.
*/
......
......@@ -68,6 +68,29 @@ public abstract class Vala.Symbol : CodeNode {
*/
public bool active { get; set; }
/**
* Specifies the accessibility of this symbol. Public accessibility
* doesn't limit access. Default accessibility limits access to this
* program or library. Private accessibility limits access to instances
* of the contained type.
*/
public SymbolAccessibility access { get; set; }
/**
* Check if this symbol is just internal API (and therefore doesn't need
* to be listed in header files for instance) by traversing parent symbols
* and checking their accessibility.
*/
public bool is_internal_symbol () {
for (Symbol sym = this; null != sym; sym = sym.parent_symbol) {
if (SymbolAccessibility.PRIVATE == sym.access) {
return true;
}
}
return false;
}
public Scope scope {
get { return _scope; }
}
......@@ -196,3 +219,11 @@ public abstract class Vala.Symbol : CodeNode {
return result.str;
}
}
public enum Vala.SymbolAccessibility {
PRIVATE,
INTERNAL,
PROTECTED,
PUBLIC
}
......@@ -239,7 +239,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
var cb = new Callback (node.name, parse_param (f_node.result), current_source_reference);
cb.access = MemberAccessibility.PUBLIC;
cb.access = SymbolAccessibility.PUBLIC;
foreach (weak IdlNodeParam param in f_node.parameters) {
weak IdlNode param_node = (IdlNode) param;
......@@ -277,7 +277,7 @@ public class Vala.GIdlParser : CodeVisitor {
var st = ns.scope.lookup (name) as Struct;
if (st == null) {
st = new Struct (name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
st.access = SymbolAccessibility.PUBLIC;
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
......@@ -318,7 +318,7 @@ public class Vala.GIdlParser : CodeVisitor {
var cl = ns.scope.lookup (name) as Class;
if (cl == null) {
cl = new Class (name, current_source_reference);
cl.access = MemberAccessibility.PUBLIC;
cl.access = SymbolAccessibility.PUBLIC;
var cl_attributes = get_attributes (node.name);
if (cl_attributes != null) {
......@@ -388,7 +388,7 @@ public class Vala.GIdlParser : CodeVisitor {
var st = ns.scope.lookup (name) as Struct;
if (st == null) {
st = new Struct (name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
st.access = SymbolAccessibility.PUBLIC;
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
......@@ -426,7 +426,7 @@ public class Vala.GIdlParser : CodeVisitor {
var cl = ns.scope.lookup (name) as Class;
if (cl == null) {
cl = new Class (name, current_source_reference);
cl.access = MemberAccessibility.PUBLIC;
cl.access = SymbolAccessibility.PUBLIC;
var cl_attributes = get_attributes (node.name);
if (cl_attributes != null) {
......@@ -488,7 +488,7 @@ public class Vala.GIdlParser : CodeVisitor {
weak IdlNode node = (IdlNode) en_node;
var en = new Enum (node.name, current_source_reference);
en.access = MemberAccessibility.PUBLIC;
en.access = SymbolAccessibility.PUBLIC;
string common_prefix = null;
......@@ -527,7 +527,7 @@ public class Vala.GIdlParser : CodeVisitor {
var cl = ns.scope.lookup (name) as Class;
if (cl == null) {
cl = new Class (name, current_source_reference);
cl.access = MemberAccessibility.PUBLIC;
cl.access = SymbolAccessibility.PUBLIC;
var attributes = get_attributes (node.gtype_name);
if (attributes != null) {
......@@ -631,7 +631,7 @@ public class Vala.GIdlParser : CodeVisitor {
var iface = ns.scope.lookup (name) as Interface;
if (iface == null) {
iface = new Interface (name, current_source_reference);
iface.access = MemberAccessibility.PUBLIC;
iface.access = SymbolAccessibility.PUBLIC;
var attributes = get_attributes (node.gtype_name);
if (attributes != null) {
......@@ -918,7 +918,7 @@ public class Vala.GIdlParser : CodeVisitor {
} else {
m = new Method (node.name, return_type, current_source_reference);
}
m.access = MemberAccessibility.PUBLIC;
m.access = SymbolAccessibility.PUBLIC;
m.is_virtual = is_virtual && !is_interface;
m.is_abstract = is_virtual && is_interface;
......@@ -1086,7 +1086,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
var prop = new Property (fix_prop_name (node.name), parse_type (prop_node.type), get_acc, set_acc, current_source_reference);
prop.access = MemberAccessibility.PUBLIC;
prop.access = SymbolAccessibility.PUBLIC;
prop.interface_only = true;
var attributes = get_attributes ("%s:%s".printf (current_data_type.get_cname (), node.name));
......@@ -1158,7 +1158,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
var field = new Field (node.name, type, null, current_source_reference);
field.access = MemberAccessibility.PUBLIC;
field.access = SymbolAccessibility.PUBLIC;
return field;
}
......@@ -1185,7 +1185,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
var sig = new Signal (fix_prop_name (node.name), parse_param (sig_node.result), current_source_reference);
sig.access = MemberAccessibility.PUBLIC;
sig.access = SymbolAccessibility.PUBLIC;
var attributes = get_attributes ("%s::%s".printf (current_data_type.get_cname (), sig.name));
if (attributes != null) {
......
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