Commit 02f7d056 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

don't expose private classes in public header files

2007-07-25  Juerg Billeter  <j@bitron.ch>

	* gobject/valacodegenerator.vala, gobject/valacodegeneratorclass.vala,
	  gobject/valacodegeneratormethod.vala,
	  gobject/valacodegeneratorstruct.vala: don't expose private classes in
	  public header files

svn path=/trunk/; revision=386
parent 04540faa
2007-07-25 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala, gobject/valacodegeneratorclass.vala,
gobject/valacodegeneratormethod.vala,
gobject/valacodegeneratorstruct.vala: don't expose private classes in
public header files
2007-07-25 Jürg Billeter <j@bitron.ch>
* gobject/valacodegeneratorassignment.vala: ensure that index expression
......
......@@ -488,7 +488,12 @@ public class Vala.CodeGenerator : CodeVisitor {
function.add_parameter (cvalueparam);
}
header_type_member_declaration.append (function.copy ());
if (t.access != MemberAccessibility.PRIVATE) {
header_type_member_declaration.append (function.copy ());
} else {
function.modifiers |= CCodeModifiers.STATIC;
source_type_member_declaration.append (function.copy ());
}
var block = new CCodeBlock ();
function.block = block;
......@@ -555,7 +560,12 @@ public class Vala.CodeGenerator : CodeVisitor {
}
if (!is_virtual) {
header_type_member_declaration.append (function.copy ());
if (t.access != MemberAccessibility.PRIVATE) {
header_type_member_declaration.append (function.copy ());
} else {
function.modifiers |= CCodeModifiers.STATIC;
source_type_member_declaration.append (function.copy ());
}
}
if (acc.body != null) {
......
......@@ -49,44 +49,53 @@ public class Vala.CodeGenerator {
prop_enum.add_value ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null)), null);
instance_init_fragment = new CCodeFragment ();
instance_dispose_fragment = new CCodeFragment ();
CCodeFragment decl_frag;
CCodeFragment def_frag;
if (cl.access != MemberAccessibility.PRIVATE) {
decl_frag = header_type_declaration;
def_frag = header_type_definition;
} else {
decl_frag = source_type_member_declaration;
def_frag = source_type_member_declaration;
}
header_type_declaration.append (new CCodeNewline ());
decl_frag.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (cl.get_lower_case_cname (null));
header_type_declaration.append (new CCodeMacroReplacement (cl.get_upper_case_cname ("TYPE_"), macro));
decl_frag.append (new CCodeMacroReplacement (cl.get_upper_case_cname ("TYPE_"), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname (null)), macro));
decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_CLASS_CAST ((klass), %s, %sClass))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (cl.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname ("IS_")), macro));
decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname ("IS_")), macro));
macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (cl.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname ("IS_")), macro));
decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname ("IS_")), macro));
macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
header_type_declaration.append (new CCodeNewline ());
decl_frag.append (new CCodeMacroReplacement ("%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
decl_frag.append (new CCodeNewline ());
if (cl.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
}
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
instance_struct.add_field (cl.base_class.get_cname (), "parent");
instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent");
if (cl.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (cl.source_reference.comment));
def_frag.append (new CCodeComment (cl.source_reference.comment));
}
header_type_definition.append (instance_struct);
header_type_definition.append (type_struct);
def_frag.append (instance_struct);
def_frag.append (type_struct);
/* only add the *Private struct if it is not empty, i.e. we actually have private data */
if (cl.has_private_fields) {
source_type_member_declaration.append (instance_priv_struct);
......@@ -119,7 +128,11 @@ public class Vala.CodeGenerator {
var type_fun = new ClassRegisterFunction (cl);
type_fun.init_from_type (in_plugin);
header_type_member_declaration.append (type_fun.get_declaration ());
if (cl.access != MemberAccessibility.PRIVATE) {
header_type_member_declaration.append (type_fun.get_declaration ());
} else {
source_type_member_declaration.append (type_fun.get_declaration ());
}
source_type_member_definition.append (type_fun.get_definition ());
if (in_plugin) {
......
......@@ -184,10 +184,16 @@ public class Vala.CodeGenerator {
}
}
bool visible = m.access != MemberAccessibility.PRIVATE;
if (m.parent_symbol is DataType) {
var dt = (DataType) m.parent_symbol;
visible = visible && dt.access != MemberAccessibility.PRIVATE;
}
/* real function declaration and definition not needed
* for abstract methods */
if (!m.is_abstract) {
if (m.access != MemberAccessibility.PRIVATE && m.base_method == null && m.base_interface_method == null) {
if (visible && m.base_method == null && m.base_interface_method == null) {
/* public methods need function declaration in
* header file except virtual/overridden methods */
header_type_member_declaration.append (function.copy ());
......@@ -333,7 +339,12 @@ public class Vala.CodeGenerator {
vblock.add_statement (new CCodeReturnStatement (vcall));
}
header_type_member_declaration.append (vfunc.copy ());
if (visible) {
header_type_member_declaration.append (vfunc.copy ());
} else {
vfunc.modifiers |= CCodeModifiers.STATIC;
source_type_member_declaration.append (vfunc.copy ());
}
vfunc.block = vblock;
......
......@@ -32,14 +32,24 @@ public class Vala.CodeGenerator {
instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
instance_dispose_fragment = null;
CCodeFragment decl_frag;
CCodeFragment def_frag;
if (st.access != MemberAccessibility.PRIVATE) {
decl_frag = header_type_declaration;
def_frag = header_type_definition;
} else {
decl_frag = source_type_member_declaration;
def_frag = source_type_member_declaration;
}
if (st.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
}
if (st.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (st.source_reference.comment));
def_frag.append (new CCodeComment (st.source_reference.comment));
}
header_type_definition.append (instance_struct);
def_frag.append (instance_struct);
st.accept_children (this);
......
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