Commit 0e8ad38d authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

add possibility to change interface type struct cname, default to `Iface'

2006-08-24  Jürg Billeter  <j@bitron.ch>

	* vala/valaattributeprocessor.vala, vala/valacodegenerator.vala,
	  vala/valainterface.vala, vala/valainterfaceregisterfunction.vala: add
	  possibility to change interface type struct cname, default to `Iface'
	  suffix (reported by Dominique Würtz)

svn path=/trunk/; revision=112
parent 5dc789ba
2006-08-24 Jürg Billeter <j@bitron.ch>
* vala/valaattributeprocessor.vala, vala/valacodegenerator.vala,
vala/valainterface.vala, vala/valainterfaceregisterfunction.vala: add
possibility to change interface type struct cname, default to `Iface'
suffix (reported by Dominique Würtz)
2006-08-23 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: support calling non-abstract interface
......
......@@ -39,12 +39,16 @@ public class Vala.AttributeProcessor : CodeVisitor {
ns.process_attributes ();
}
public override void visit_begin_class (Class! cl) {
cl.process_attributes ();
}
public override void visit_begin_struct (Struct! st) {
st.process_attributes ();
}
public override void visit_begin_class (Class! cl) {
cl.process_attributes ();
public override void visit_begin_interface (Interface! iface) {
iface.process_attributes ();
}
public override void visit_begin_enum (Enum! en) {
......
......@@ -508,7 +508,7 @@ public class Vala.CodeGenerator : CodeVisitor {
private void add_interface_init_function (Class! cl, Interface! iface) {
var iface_init = new CCodeFunction ("%s_%s_interface_init".printf (cl.get_lower_case_cname (null), iface.get_lower_case_cname (null)), "void");
iface_init.add_parameter (new CCodeFormalParameter ("iface", "%sInterface *".printf (iface.get_cname ())));
iface_init.add_parameter (new CCodeFormalParameter ("iface", "%s *".printf (iface.get_type_cname ())));
iface_init.modifiers = CCodeModifiers.STATIC;
var init_block = new CCodeBlock ();
......@@ -783,7 +783,7 @@ public class Vala.CodeGenerator : CodeVisitor {
current_symbol = iface.symbol;
current_type_symbol = iface.symbol;
type_struct = new CCodeStruct ("_%sInterface".printf (iface.get_cname ()));
type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
header_type_declaration.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
......@@ -795,14 +795,14 @@ public class Vala.CodeGenerator : CodeVisitor {
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %sInterface))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_type_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
header_type_declaration.append (new CCodeNewline ());
if (iface.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sInterface".printf (iface.get_cname ()))));
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
}
type_struct.add_field ("GTypeInterface", "parent");
......
......@@ -34,6 +34,10 @@ public class Vala.Interface : DataType {
private List<Property> properties;
private List<Signal> signals;
private string cname;
private string lower_case_csuffix;
private string type_cname;
/**
* Creates a new interface.
*
......@@ -129,9 +133,6 @@ public class Vala.Interface : DataType {
return signals.copy ();
}
private string cname;
private string lower_case_csuffix;
public override string get_cname () {
if (cname == null) {
cname = "%s%s".printf (@namespace.get_cprefix (), name);
......@@ -225,4 +226,50 @@ public class Vala.Interface : DataType {
return false;
}
private void process_ccode_attribute (Attribute! a) {
foreach (NamedArgument arg in a.args) {
if (arg.name == "type_cname") {
/* this will already be checked during semantic analysis */
if (arg.argument is LiteralExpression) {
var lit = ((LiteralExpression) arg.argument).literal;
if (lit is StringLiteral) {
set_type_cname (((StringLiteral) lit).eval ());
}
}
}
}
}
/**
* Process all associated attributes.
*/
public void process_attributes () {
foreach (Attribute a in attributes) {
if (a.name == "CCode") {
process_ccode_attribute (a);
}
}
}
/**
* Returns the name of the type struct as it is used in C code.
*
* @return the type struct name to be used in C code
*/
public string get_type_cname () {
if (type_cname == null) {
type_cname = "%sIface".printf (get_cname ());
}
return type_cname;
}
/**
* Sets the name of the type struct as it is used in C code.
*
* @param type_cname the type struct name to be used in C code
*/
public void set_type_cname (string! type_cname) {
this.type_cname = type_cname;
}
}
......@@ -40,7 +40,7 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
}
public override ref string! get_type_struct_name () {
return "%sInterface".printf (interface_reference.get_cname ());
return interface_reference.get_type_cname ();
}
public override ref string! get_class_init_func_name () {
......
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