vala r1260 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1260 - in trunk: . gobject vala
- Date: Sat, 19 Apr 2008 07:06:38 +0100 (BST)
Author: juergbi
Date: Sat Apr 19 06:06:38 2008
New Revision: 1260
URL: http://svn.gnome.org/viewvc/vala?rev=1260&view=rev
Log:
2008-04-19 Juerg Billeter <j bitron ch>
* vala/valaclass.vala, vala/valainterface.vala, gobject/Makefile.am,
gobject/valaccodeassignmentbinding.vala,
gobject/valaccodebinding.vala, gobject/valaccodeclassbinding.vala,
gobject/valaccodegenerator.vala,
gobject/valaccodeinterfacebinding.vala,
gobject/valaccodetypesymbolbinding.vala:
Add CCodeTypesymbolBinding, CCodeClassBinding, and
CCodeInterfaceBinding classes
Added:
trunk/gobject/valaccodeclassbinding.vala
- copied, changed from r1256, /trunk/gobject/valaccodegeneratorclass.vala
trunk/gobject/valaccodeinterfacebinding.vala
- copied, changed from r1256, /trunk/gobject/valaccodegeneratorinterface.vala
trunk/gobject/valaccodetypesymbolbinding.vala
Removed:
trunk/gobject/valaccodegeneratorclass.vala
trunk/gobject/valaccodegeneratorinterface.vala
Modified:
trunk/ChangeLog
trunk/gobject/Makefile.am
trunk/gobject/valaccodeassignmentbinding.vala
trunk/gobject/valaccodebinding.vala
trunk/gobject/valaccodegenerator.vala
trunk/vala/valaclass.vala
trunk/vala/valainterface.vala
Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am (original)
+++ trunk/gobject/Makefile.am Sat Apr 19 06:06:38 2008
@@ -15,19 +15,20 @@
valaccodearraycreationexpressionbinding.vala \
valaccodeassignmentbinding.vala \
valaccodebinding.vala \
+ valaccodeclassbinding.vala \
valaccodecompiler.vala \
valaccodeelementaccessbinding.vala \
valaccodeexpressionbinding.vala \
valaccodegenerator.vala \
- valaccodegeneratorclass.vala \
- valaccodegeneratorinterface.vala \
valaccodegeneratorinvocationexpression.vala \
valaccodegeneratormemberaccess.vala \
valaccodegeneratormethod.vala \
valaccodegeneratorsignal.vala \
valaccodegeneratorsourcefile.vala \
valaccodegeneratorstruct.vala \
+ valaccodeinterfacebinding.vala \
valaccodemethodbinding.vala \
+ valaccodetypesymbolbinding.vala \
valaclassregisterfunction.vala \
valadbusbindingprovider.vala \
valadbusmethod.vala \
Modified: trunk/gobject/valaccodeassignmentbinding.vala
==============================================================================
--- trunk/gobject/valaccodeassignmentbinding.vala (original)
+++ trunk/gobject/valaccodeassignmentbinding.vala Sat Apr 19 06:06:38 2008
@@ -59,7 +59,7 @@
ccomma.append_expression (cvalueinit);
// set GValue for current parameter
- var cvalueset = new CCodeFunctionCall (codegen.get_value_setter_function (prop.type_reference));
+ var cvalueset = new CCodeFunctionCall (get_value_setter_function (prop.type_reference));
cvalueset.add_argument (gvaluearg);
cvalueset.add_argument ((CCodeExpression) assignment.right.ccodenode);
ccomma.append_expression (cvalueset);
Modified: trunk/gobject/valaccodebinding.vala
==============================================================================
--- trunk/gobject/valaccodebinding.vala (original)
+++ trunk/gobject/valaccodebinding.vala Sat Apr 19 06:06:38 2008
@@ -36,6 +36,14 @@
*/
public abstract void emit ();
+ public CCodeIdentifier get_value_setter_function (DataType type_reference) {
+ if (type_reference.data_type != null) {
+ return new CCodeIdentifier (type_reference.data_type.get_set_value_function ());
+ } else {
+ return new CCodeIdentifier ("g_value_set_pointer");
+ }
+ }
+
public CCodeBinding? code_binding (CodeNode node) {
return (CCodeBinding) node.get_code_binding (codegen);
}
Copied: trunk/gobject/valaccodeclassbinding.vala (from r1256, /trunk/gobject/valaccodegeneratorclass.vala)
==============================================================================
--- /trunk/gobject/valaccodegeneratorclass.vala (original)
+++ trunk/gobject/valaccodeclassbinding.vala Sat Apr 19 06:06:38 2008
@@ -1,4 +1,4 @@
-/* valaccodegeneratorclass.vala
+/* valaccodeclassbinding.vala
*
* Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
*
@@ -23,25 +23,32 @@
using GLib;
-public class Vala.CCodeGenerator {
- public override void visit_class (Class cl) {
- var old_symbol = current_symbol;
- var old_type_symbol = current_type_symbol;
- var old_class = current_class;
- var old_instance_struct = instance_struct;
- var old_type_struct = type_struct;
- var old_instance_priv_struct = instance_priv_struct;
- var old_prop_enum = prop_enum;
- var old_class_init_fragment = class_init_fragment;
- var old_instance_init_fragment = instance_init_fragment;
- var old_instance_dispose_fragment = instance_dispose_fragment;
- current_symbol = cl;
- current_type_symbol = cl;
- current_class = cl;
-
- bool is_gtypeinstance = cl.is_subtype_of (gtypeinstance_type);
- bool is_gobject = cl.is_subtype_of (gobject_type);
- bool is_fundamental = (cl.base_class == gtypeinstance_type);
+public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
+ public Class cl { get; set; }
+
+ public CCodeClassBinding (CCodeGenerator codegen, Class cl) {
+ this.cl = cl;
+ this.codegen = codegen;
+ }
+
+ public override void emit () {
+ var old_symbol = codegen.current_symbol;
+ var old_type_symbol = codegen.current_type_symbol;
+ var old_class = codegen.current_class;
+ var old_instance_struct = codegen.instance_struct;
+ var old_type_struct = codegen.type_struct;
+ var old_instance_priv_struct = codegen.instance_priv_struct;
+ var old_prop_enum = codegen.prop_enum;
+ var old_class_init_fragment = codegen.class_init_fragment;
+ var old_instance_init_fragment = codegen.instance_init_fragment;
+ var old_instance_dispose_fragment = codegen.instance_dispose_fragment;
+ codegen.current_symbol = cl;
+ codegen.current_type_symbol = cl;
+ codegen.current_class = cl;
+
+ bool is_gtypeinstance = cl.is_subtype_of (codegen.gtypeinstance_type);
+ bool is_gobject = cl.is_subtype_of (codegen.gobject_type);
+ bool is_fundamental = (cl.base_class == codegen.gtypeinstance_type);
if (cl.get_cname().len () < 3) {
cl.error = true;
@@ -50,24 +57,24 @@
}
if (!cl.is_static) {
- instance_struct = new CCodeStruct ("_%s".printf (cl.get_cname ()));
- type_struct = new CCodeStruct ("_%sClass".printf (cl.get_cname ()));
- instance_priv_struct = new CCodeStruct ("_%sPrivate".printf (cl.get_cname ()));
- prop_enum = new CCodeEnum ();
- prop_enum.add_value (new CCodeEnumValue ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null))));
- class_init_fragment = new CCodeFragment ();
- instance_init_fragment = new CCodeFragment ();
- instance_dispose_fragment = new CCodeFragment ();
+ codegen.instance_struct = new CCodeStruct ("_%s".printf (cl.get_cname ()));
+ codegen.type_struct = new CCodeStruct ("_%sClass".printf (cl.get_cname ()));
+ codegen.instance_priv_struct = new CCodeStruct ("_%sPrivate".printf (cl.get_cname ()));
+ codegen.prop_enum = new CCodeEnum ();
+ codegen.prop_enum.add_value (new CCodeEnumValue ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null))));
+ codegen.class_init_fragment = new CCodeFragment ();
+ codegen.instance_init_fragment = new CCodeFragment ();
+ codegen.instance_dispose_fragment = new CCodeFragment ();
}
CCodeFragment decl_frag;
CCodeFragment def_frag;
if (cl.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_frag = codegen.header_type_declaration;
+ def_frag = codegen.header_type_definition;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_frag = codegen.source_type_declaration;
+ def_frag = codegen.source_type_definition;
}
if (is_gtypeinstance) {
@@ -94,28 +101,28 @@
if (!cl.is_static && cl.source_reference.file.cycle == null) {
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
+ decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
}
if (cl.base_class != null) {
- instance_struct.add_field (cl.base_class.get_cname (), "parent_instance");
+ codegen.instance_struct.add_field (cl.base_class.get_cname (), "parent_instance");
if (is_fundamental) {
- instance_struct.add_field ("volatile int", "ref_count");
+ codegen.instance_struct.add_field ("volatile int", "ref_count");
}
}
if (is_gtypeinstance) {
if (cl.source_reference.file.cycle == null) {
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
+ decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
}
- decl_frag.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 (codegen.instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
- instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
+ codegen.instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
if (is_fundamental) {
- type_struct.add_field ("GTypeClass", "parent_class");
- type_struct.add_field ("void", "(*finalize) (%s *self)".printf (cl.get_cname ()));
+ codegen.type_struct.add_field ("GTypeClass", "parent_class");
+ codegen.type_struct.add_field ("void", "(*finalize) (%s *self)".printf (cl.get_cname ()));
} else {
- type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent_class");
+ codegen.type_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent_class");
}
}
@@ -123,26 +130,26 @@
if (cl.source_reference.comment != null) {
def_frag.append (new CCodeComment (cl.source_reference.comment));
}
- def_frag.append (instance_struct);
+ def_frag.append (codegen.instance_struct);
}
if (is_gtypeinstance) {
- def_frag.append (type_struct);
+ def_frag.append (codegen.type_struct);
/* only add the *Private struct if it is not empty, i.e. we actually have private data */
if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
- source_type_member_declaration.append (instance_priv_struct);
+ codegen.source_type_member_declaration.append (codegen.instance_priv_struct);
var macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ());
- source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
+ codegen.source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
}
- source_type_member_declaration.append (prop_enum);
+ codegen.source_type_member_declaration.append (codegen.prop_enum);
}
- cl.accept_children (this);
+ cl.accept_children (codegen);
if (is_gtypeinstance) {
if (is_fundamental) {
var ref_count = new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "ref_count"), new CCodeConstant ("1"));
- instance_init_fragment.append (new CCodeExpressionStatement (ref_count));
+ codegen.instance_init_fragment.append (new CCodeExpressionStatement (ref_count));
} else if (is_gobject) {
if (class_has_readable_properties (cl) || cl.get_type_parameters ().size > 0) {
add_get_property_function (cl);
@@ -168,19 +175,19 @@
}
var type_fun = new ClassRegisterFunction (cl);
- type_fun.init_from_type (in_plugin);
+ type_fun.init_from_type (codegen.in_plugin);
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (type_fun.get_declaration ());
+ codegen.header_type_member_declaration.append (type_fun.get_declaration ());
} else {
- source_type_member_declaration.append (type_fun.get_declaration ());
+ codegen.source_type_member_declaration.append (type_fun.get_declaration ());
}
- source_type_member_definition.append (type_fun.get_definition ());
+ codegen.source_type_member_definition.append (type_fun.get_definition ());
- if (in_plugin) {
+ if (codegen.in_plugin) {
// FIXME resolve potential dependency issues, i.e. base types have to be registered before derived types
var register_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_register_type".printf (cl.get_lower_case_cname (null))));
- register_call.add_argument (new CCodeIdentifier (module_init_param_name));
- module_init_fragment.append (new CCodeExpressionStatement (register_call));
+ register_call.add_argument (new CCodeIdentifier (codegen.module_init_param_name));
+ codegen.module_init_fragment.append (new CCodeExpressionStatement (register_call));
}
if (is_fundamental) {
@@ -195,11 +202,11 @@
unref_fun.add_parameter (new CCodeFormalParameter ("instance", "gpointer"));
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (ref_fun.copy ());
- header_type_member_declaration.append (unref_fun.copy ());
+ codegen.header_type_member_declaration.append (ref_fun.copy ());
+ codegen.header_type_member_declaration.append (unref_fun.copy ());
} else {
- source_type_member_declaration.append (ref_fun.copy ());
- source_type_member_declaration.append (unref_fun.copy ());
+ codegen.source_type_member_declaration.append (ref_fun.copy ());
+ codegen.source_type_member_declaration.append (unref_fun.copy ());
}
var ref_block = new CCodeBlock ();
@@ -236,8 +243,8 @@
ref_fun.block = ref_block;
unref_fun.block = unref_block;
- source_type_member_definition.append (ref_fun);
- source_type_member_definition.append (unref_fun);
+ codegen.source_type_member_definition.append (ref_fun);
+ codegen.source_type_member_definition.append (unref_fun);
}
} else if (!cl.is_static) {
var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
@@ -248,14 +255,14 @@
function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ codegen.header_type_member_declaration.append (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ codegen.source_type_member_declaration.append (function.copy ());
}
var cblock = new CCodeBlock ();
- cblock.add_statement (instance_dispose_fragment);
+ cblock.add_statement (codegen.instance_dispose_fragment);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
@@ -264,18 +271,18 @@
function.block = cblock;
- source_type_member_definition.append (function);
+ codegen.source_type_member_definition.append (function);
}
- current_type_symbol = old_type_symbol;
- current_class = old_class;
- instance_struct = old_instance_struct;
- type_struct = old_type_struct;
- instance_priv_struct = old_instance_priv_struct;
- prop_enum = old_prop_enum;
- class_init_fragment = old_class_init_fragment;
- instance_init_fragment = old_instance_init_fragment;
- instance_dispose_fragment = old_instance_dispose_fragment;
+ codegen.current_type_symbol = old_type_symbol;
+ codegen.current_class = old_class;
+ codegen.instance_struct = old_instance_struct;
+ codegen.type_struct = old_type_struct;
+ codegen.instance_priv_struct = old_instance_priv_struct;
+ codegen.prop_enum = old_prop_enum;
+ codegen.class_init_fragment = old_class_init_fragment;
+ codegen.instance_init_fragment = old_instance_init_fragment;
+ codegen.instance_dispose_fragment = old_instance_dispose_fragment;
}
private void add_class_init_function (Class cl) {
@@ -294,7 +301,7 @@
parent_var_decl.initializer = new CCodeConstant ("NULL");
parent_decl.add_declarator (parent_var_decl);
parent_decl.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (parent_decl);
+ codegen.source_type_member_declaration.append (parent_decl);
ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_peek_parent"));
ccall.add_argument (new CCodeIdentifier ("klass"));
var parent_assignment = new CCodeAssignment (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))), ccall);
@@ -308,7 +315,7 @@
init_block.add_statement (new CCodeExpressionStatement (ccall));
}
- if (cl.is_subtype_of (gobject_type)) {
+ if (cl.is_subtype_of (codegen.gobject_type)) {
/* set property handlers */
ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
ccall.add_argument (new CCodeIdentifier ("klass"));
@@ -346,7 +353,7 @@
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccast, m.base_method.vfunc_name), new CCodeIdentifier (m.get_real_cname ()))));
}
- if (cl.is_subtype_of (gobject_type)) {
+ if (cl.is_subtype_of (codegen.gobject_type)) {
/* create type, dup_func, and destroy_func properties for generic types */
foreach (TypeParameter type_param in cl.get_type_parameters ()) {
string func_name, enum_value;
@@ -367,9 +374,9 @@
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
- prop_enum.add_value (new CCodeEnumValue (enum_value));
+ codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
- instance_priv_struct.add_field ("GType", func_name);
+ codegen.instance_priv_struct.add_field ("GType", func_name);
func_name = "%s_dup_func".printf (type_param.name.down ());
@@ -385,9 +392,9 @@
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
- prop_enum.add_value (new CCodeEnumValue (enum_value));
+ codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
- instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
+ codegen.instance_priv_struct.add_field ("GBoxedCopyFunc", func_name);
func_name = "%s_destroy_func".printf (type_param.name.down ());
@@ -403,9 +410,9 @@
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
- prop_enum.add_value (new CCodeEnumValue (enum_value));
+ codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
- instance_priv_struct.add_field ("GDestroyNotify", func_name);
+ codegen.instance_priv_struct.add_field ("GDestroyNotify", func_name);
}
/* create properties */
@@ -443,9 +450,9 @@
}
}
- init_block.add_statement (class_init_fragment);
+ init_block.add_statement (codegen.class_init_fragment);
- source_type_member_definition.append (class_init);
+ codegen.source_type_member_definition.append (class_init);
}
private void add_interface_init_function (Class cl, Interface iface) {
@@ -465,7 +472,7 @@
parent_var_decl.initializer = new CCodeConstant ("NULL");
parent_decl.add_declarator (parent_var_decl);
parent_decl.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (parent_decl);
+ codegen.source_type_member_declaration.append (parent_decl);
ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_peek_parent"));
ccall.add_argument (new CCodeIdentifier ("iface"));
var parent_assignment = new CCodeAssignment (new CCodeIdentifier (parent_iface_var), ccall);
@@ -490,7 +497,7 @@
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ciface, m.base_interface_method.vfunc_name), new CCodeIdentifier (cname))));
}
- source_type_member_definition.append (iface_init);
+ codegen.source_type_member_definition.append (iface_init);
}
private void add_instance_init_function (Class cl) {
@@ -507,7 +514,7 @@
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), ccall)));
}
- init_block.add_statement (instance_init_fragment);
+ init_block.add_statement (codegen.instance_init_fragment);
var init_sym = cl.scope.lookup ("init");
if (init_sym != null) {
@@ -515,16 +522,16 @@
init_block.add_statement (init_fun.body.ccodenode);
}
- source_type_member_definition.append (instance_init);
+ codegen.source_type_member_definition.append (instance_init);
}
private void add_dispose_function (Class cl) {
- function = new CCodeFunction ("%s_dispose".printf (cl.get_lower_case_cname (null)), "void");
+ var function = new CCodeFunction ("%s_dispose".printf (cl.get_lower_case_cname (null)), "void");
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeFormalParameter ("obj", "GObject *"));
- source_type_member_declaration.append (function.copy ());
+ codegen.source_type_member_declaration.append (function.copy ());
var cblock = new CCodeBlock ();
@@ -540,7 +547,7 @@
cblock.add_statement ((CCodeBlock) cl.destructor.body.ccodenode);
}
- cblock.add_statement (instance_dispose_fragment);
+ cblock.add_statement (codegen.instance_dispose_fragment);
// chain up to dispose function of the base class
var ccast = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
@@ -552,15 +559,7 @@
function.block = cblock;
- source_type_member_definition.append (function);
- }
-
- public CCodeIdentifier get_value_setter_function (DataType type_reference) {
- if (type_reference.data_type != null) {
- return new CCodeIdentifier (type_reference.data_type.get_set_value_function ());
- } else {
- return new CCodeIdentifier ("g_value_set_pointer");
- }
+ codegen.source_type_member_definition.append (function);
}
private bool class_has_readable_properties (Class cl) {
@@ -633,7 +632,7 @@
get_prop.block = block;
- source_type_member_definition.append (get_prop);
+ codegen.source_type_member_definition.append (get_prop);
}
private void add_set_property_function (Class cl) {
@@ -730,7 +729,7 @@
set_prop.block = block;
- source_type_member_definition.append (set_prop);
+ codegen.source_type_member_definition.append (set_prop);
}
private CCodeStatement get_invalid_property_id_warn_statement () {
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Sat Apr 19 06:06:38 2008
@@ -30,52 +30,52 @@
public class Vala.CCodeGenerator : CodeGenerator {
private CodeContext context;
- Symbol root_symbol;
- Symbol current_symbol;
+ public Symbol root_symbol;
+ public Symbol current_symbol;
public Typesymbol current_type_symbol;
public Class current_class;
- Method current_method;
- DataType current_return_type;
- TryStatement current_try;
- PropertyAccessor current_property_accessor;
-
- CCodeFragment header_begin;
- CCodeFragment header_type_declaration;
- CCodeFragment header_type_definition;
- CCodeFragment header_type_member_declaration;
- CCodeFragment header_constant_declaration;
- CCodeFragment source_begin;
- CCodeFragment source_include_directives;
- CCodeFragment source_type_declaration;
- CCodeFragment source_type_definition;
+ public Method current_method;
+ public DataType current_return_type;
+ public TryStatement current_try;
+ public PropertyAccessor current_property_accessor;
+
+ public CCodeFragment header_begin;
+ public CCodeFragment header_type_declaration;
+ public CCodeFragment header_type_definition;
+ public CCodeFragment header_type_member_declaration;
+ public CCodeFragment header_constant_declaration;
+ public CCodeFragment source_begin;
+ public CCodeFragment source_include_directives;
+ public CCodeFragment source_type_declaration;
+ public CCodeFragment source_type_definition;
public CCodeFragment source_type_member_declaration;
- CCodeFragment source_constant_declaration;
- CCodeFragment source_signal_marshaller_declaration;
+ public CCodeFragment source_constant_declaration;
+ public CCodeFragment source_signal_marshaller_declaration;
public CCodeFragment source_type_member_definition;
- CCodeFragment class_init_fragment;
- CCodeFragment instance_init_fragment;
- CCodeFragment instance_dispose_fragment;
- CCodeFragment source_signal_marshaller_definition;
- CCodeFragment module_init_fragment;
-
- CCodeStruct instance_struct;
- CCodeStruct type_struct;
- CCodeStruct instance_priv_struct;
- CCodeEnum prop_enum;
- CCodeEnum cenum;
- CCodeFunction function;
- CCodeBlock block;
+ public CCodeFragment class_init_fragment;
+ public CCodeFragment instance_init_fragment;
+ public CCodeFragment instance_dispose_fragment;
+ public CCodeFragment source_signal_marshaller_definition;
+ public CCodeFragment module_init_fragment;
+
+ public CCodeStruct instance_struct;
+ public CCodeStruct type_struct;
+ public CCodeStruct instance_priv_struct;
+ public CCodeEnum prop_enum;
+ public CCodeEnum cenum;
+ public CCodeFunction function;
+ public CCodeBlock block;
/* all temporary variables */
public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
/* temporary variables that own their content */
- ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
+ public ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
/* cache to check whether a certain marshaller has been created yet */
- Gee.Set<string> user_marshal_set;
+ public Gee.Set<string> user_marshal_set;
/* (constant) hash table with all predefined marshallers */
- Gee.Set<string> predefined_marshal_set;
+ public Gee.Set<string> predefined_marshal_set;
/* (constant) hash table with all C keywords */
- Gee.Set<string> c_keywords;
+ public Gee.Set<string> c_keywords;
private int next_temp_var_id = 0;
private int current_try_id = 0;
@@ -117,8 +117,8 @@
Method substring_method;
- private bool in_plugin = false;
- private string module_init_param_name;
+ public bool in_plugin = false;
+ public string module_init_param_name;
private bool string_h_needed;
private bool requires_free_checked;
@@ -269,6 +269,14 @@
}
}
+ public override void visit_class (Class cl) {
+ code_binding (cl).emit ();
+ }
+
+ public override void visit_interface (Interface iface) {
+ code_binding (iface).emit ();
+ }
+
public override void visit_enum (Enum en) {
cenum = new CCodeEnum (en.get_cname ());
@@ -3570,7 +3578,7 @@
}
public override CodeBinding? create_class_binding (Class node) {
- return null;
+ return new CCodeClassBinding (this, node);
}
public override CodeBinding? create_struct_binding (Struct node) {
@@ -3578,7 +3586,7 @@
}
public override CodeBinding? create_interface_binding (Interface node) {
- return null;
+ return new CCodeInterfaceBinding (this, node);
}
public override CodeBinding? create_enum_binding (Enum node) {
Copied: trunk/gobject/valaccodeinterfacebinding.vala (from r1256, /trunk/gobject/valaccodegeneratorinterface.vala)
==============================================================================
--- /trunk/gobject/valaccodegeneratorinterface.vala (original)
+++ trunk/gobject/valaccodeinterfacebinding.vala Sat Apr 19 06:06:38 2008
@@ -1,4 +1,4 @@
-/* valaccodegeneratorinterface.vala
+/* valaccodeinterfacebinding.vala
*
* Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
*
@@ -23,10 +23,17 @@
using GLib;
-public class Vala.CCodeGenerator {
- public override void visit_interface (Interface iface) {
- current_symbol = iface;
- current_type_symbol = iface;
+public class Vala.CCodeInterfaceBinding : CCodeTypesymbolBinding {
+ public Interface iface { get; set; }
+
+ public CCodeInterfaceBinding (CCodeGenerator codegen, Interface iface) {
+ this.iface = iface;
+ this.codegen = codegen;
+ }
+
+ public override void emit () {
+ codegen.current_symbol = iface;
+ codegen.current_type_symbol = iface;
if (iface.get_cname().len () < 3) {
iface.error = true;
@@ -37,15 +44,15 @@
CCodeFragment decl_frag;
CCodeFragment def_frag;
if (iface.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_frag = codegen.header_type_declaration;
+ def_frag = codegen.header_type_definition;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_frag = codegen.source_type_declaration;
+ def_frag = codegen.source_type_definition;
}
if (!iface.is_static && !iface.declaration_only) {
- type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
+ codegen.type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
decl_frag.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
@@ -64,18 +71,18 @@
if (iface.source_reference.file.cycle == null) {
decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
+ decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (codegen.type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
}
- type_struct.add_field ("GTypeInterface", "parent_iface");
+ codegen.type_struct.add_field ("GTypeInterface", "parent_iface");
if (iface.source_reference.comment != null) {
def_frag.append (new CCodeComment (iface.source_reference.comment));
}
- def_frag.append (type_struct);
+ def_frag.append (codegen.type_struct);
}
- iface.accept_children (this);
+ iface.accept_children (codegen);
if (!iface.is_static && !iface.declaration_only) {
add_interface_base_init_function (iface);
@@ -83,183 +90,14 @@
var type_fun = new InterfaceRegisterFunction (iface);
type_fun.init_from_type ();
if (iface.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (type_fun.get_declaration ());
+ codegen.header_type_member_declaration.append (type_fun.get_declaration ());
} else {
- source_type_member_declaration.append (type_fun.get_declaration ());
+ codegen.source_type_member_declaration.append (type_fun.get_declaration ());
}
- source_type_member_definition.append (type_fun.get_definition ());
+ codegen.source_type_member_definition.append (type_fun.get_definition ());
}
- current_type_symbol = null;
- }
-
- private CCodeFunctionCall get_param_spec (Property prop) {
- var cspec = new CCodeFunctionCall ();
- cspec.add_argument (prop.get_canonical_cconstant ());
- cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
- cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.blurb)));
- if ((prop.type_reference.data_type is Class && ((Class) prop.type_reference.data_type).is_subtype_of (gobject_type)) || prop.type_reference.data_type is Interface) {
- cspec.call = new CCodeIdentifier ("g_param_spec_object");
- cspec.add_argument (new CCodeIdentifier (prop.type_reference.data_type.get_upper_case_cname ("TYPE_")));
- } else if (prop.type_reference.data_type == string_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_string");
- cspec.add_argument (new CCodeConstant ("NULL"));
- } else if (prop.type_reference.data_type is Enum) {
- var e = prop.type_reference.data_type as Enum;
- if (e.has_type_id) {
- if (e.is_flags) {
- cspec.call = new CCodeIdentifier ("g_param_spec_flags");
- } else {
- cspec.call = new CCodeIdentifier ("g_param_spec_enum");
- }
- cspec.add_argument (new CCodeIdentifier (e.get_type_id ()));
- } else {
- if (e.is_flags) {
- cspec.call = new CCodeIdentifier ("g_param_spec_uint");
- cspec.add_argument (new CCodeConstant ("0"));
- cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
- } else {
- cspec.call = new CCodeIdentifier ("g_param_spec_int");
- cspec.add_argument (new CCodeConstant ("G_MININT"));
- cspec.add_argument (new CCodeConstant ("G_MAXINT"));
- }
- }
-
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant (prop.type_reference.data_type.get_default_value ()));
- }
- } else if (prop.type_reference.data_type == int_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_int");
- cspec.add_argument (new CCodeConstant ("G_MININT"));
- cspec.add_argument (new CCodeConstant ("G_MAXINT"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0"));
- }
- } else if (prop.type_reference.data_type == uint_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_uint");
- cspec.add_argument (new CCodeConstant ("0"));
- cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0U"));
- }
- } else if (prop.type_reference.data_type == long_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_long");
- cspec.add_argument (new CCodeConstant ("G_MINLONG"));
- cspec.add_argument (new CCodeConstant ("G_MAXLONG"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0L"));
- }
- } else if (prop.type_reference.data_type == ulong_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_ulong");
- cspec.add_argument (new CCodeConstant ("0"));
- cspec.add_argument (new CCodeConstant ("G_MAXULONG"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0UL"));
- }
- } else if (prop.type_reference.data_type == bool_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_boolean");
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("FALSE"));
- }
- } else if (prop.type_reference.data_type == float_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_float");
- cspec.add_argument (new CCodeConstant ("-G_MAXFLOAT"));
- cspec.add_argument (new CCodeConstant ("G_MAXFLOAT"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0.0F"));
- }
- } else if (prop.type_reference.data_type == double_type.data_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_double");
- cspec.add_argument (new CCodeConstant ("-G_MAXDOUBLE"));
- cspec.add_argument (new CCodeConstant ("G_MAXDOUBLE"));
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("0.0"));
- }
- } else if (prop.type_reference.data_type == gtype_type) {
- cspec.call = new CCodeIdentifier ("g_param_spec_gtype");
- if (prop.default_expression != null) {
- cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
- } else {
- cspec.add_argument (new CCodeConstant ("G_TYPE_NONE"));
- }
- } else {
- cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
- }
-
- var pflags = "G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB";
- if (prop.get_accessor != null) {
- pflags = "%s%s".printf (pflags, " | G_PARAM_READABLE");
- }
- if (prop.set_accessor != null) {
- pflags = "%s%s".printf (pflags, " | G_PARAM_WRITABLE");
- if (prop.set_accessor.construction) {
- if (prop.set_accessor.writable) {
- pflags = "%s%s".printf (pflags, " | G_PARAM_CONSTRUCT");
- } else {
- pflags = "%s%s".printf (pflags, " | G_PARAM_CONSTRUCT_ONLY");
- }
- }
- }
- cspec.add_argument (new CCodeConstant (pflags));
-
- return cspec;
- }
-
- private CCodeFunctionCall get_signal_creation (Signal sig, Typesymbol type) {
- var csignew = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_new"));
- csignew.add_argument (new CCodeConstant ("\"%s\"".printf (sig.name)));
- csignew.add_argument (new CCodeIdentifier (type.get_upper_case_cname ("TYPE_")));
- csignew.add_argument (new CCodeConstant ("G_SIGNAL_RUN_LAST"));
- csignew.add_argument (new CCodeConstant ("0"));
- csignew.add_argument (new CCodeConstant ("NULL"));
- csignew.add_argument (new CCodeConstant ("NULL"));
-
- string marshaller = get_signal_marshaller_function (sig);
-
- var marshal_arg = new CCodeIdentifier (marshaller);
- csignew.add_argument (marshal_arg);
-
- var params = sig.get_parameters ();
- var params_len = params.size;
- if (sig.return_type is PointerType || sig.return_type.type_parameter != null) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
- } else if (sig.return_type is ErrorType) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
- } else if (sig.return_type.data_type == null) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_NONE"));
- } else {
- csignew.add_argument (new CCodeConstant (sig.return_type.data_type.get_type_id ()));
- }
- csignew.add_argument (new CCodeConstant ("%d".printf (params_len)));
- foreach (FormalParameter param in params) {
- if (param.type_reference is PointerType || param.type_reference.type_parameter != null || param.direction != ParameterDirection.IN) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
- } else if (param.type_reference is ErrorType) {
- csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
- } else {
- csignew.add_argument (new CCodeConstant (param.type_reference.data_type.get_type_id ()));
- }
- }
-
- marshal_arg.name = marshaller;
-
- return csignew;
+ codegen.current_type_symbol = null;
}
private void add_interface_base_init_function (Interface iface) {
@@ -271,7 +109,7 @@
/* make sure not to run the initialization code twice */
base_init.block = new CCodeBlock ();
- var decl = new CCodeDeclaration (bool_type.get_cname ());
+ var decl = new CCodeDeclaration (codegen.bool_type.get_cname ());
decl.modifiers |= CCodeModifiers.STATIC;
decl.add_declarator (new CCodeVariableDeclarator.with_initializer ("initialized", new CCodeConstant ("FALSE")));
base_init.block.add_statement (decl);
@@ -294,6 +132,6 @@
init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, iface)));
}
- source_type_member_definition.append (base_init);
+ codegen.source_type_member_definition.append (base_init);
}
}
Added: trunk/gobject/valaccodetypesymbolbinding.vala
==============================================================================
--- (empty file)
+++ trunk/gobject/valaccodetypesymbolbinding.vala Sat Apr 19 06:06:38 2008
@@ -0,0 +1,195 @@
+/* valaccodetypesymbolbinding.vala
+ *
+ * Copyright (C) 2008 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.1 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>
+ * Raffaele Sandrini <raffaele sandrini ch>
+ */
+
+using GLib;
+
+public abstract class Vala.CCodeTypesymbolBinding : CCodeBinding {
+ public CCodeFunctionCall get_param_spec (Property prop) {
+ var cspec = new CCodeFunctionCall ();
+ cspec.add_argument (prop.get_canonical_cconstant ());
+ cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
+ cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.blurb)));
+ if ((prop.type_reference.data_type is Class && ((Class) prop.type_reference.data_type).is_subtype_of (codegen.gobject_type)) || prop.type_reference.data_type is Interface) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_object");
+ cspec.add_argument (new CCodeIdentifier (prop.type_reference.data_type.get_upper_case_cname ("TYPE_")));
+ } else if (prop.type_reference.data_type == codegen.string_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_string");
+ cspec.add_argument (new CCodeConstant ("NULL"));
+ } else if (prop.type_reference.data_type is Enum) {
+ var e = prop.type_reference.data_type as Enum;
+ if (e.has_type_id) {
+ if (e.is_flags) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_flags");
+ } else {
+ cspec.call = new CCodeIdentifier ("g_param_spec_enum");
+ }
+ cspec.add_argument (new CCodeIdentifier (e.get_type_id ()));
+ } else {
+ if (e.is_flags) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_uint");
+ cspec.add_argument (new CCodeConstant ("0"));
+ cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
+ } else {
+ cspec.call = new CCodeIdentifier ("g_param_spec_int");
+ cspec.add_argument (new CCodeConstant ("G_MININT"));
+ cspec.add_argument (new CCodeConstant ("G_MAXINT"));
+ }
+ }
+
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant (prop.type_reference.data_type.get_default_value ()));
+ }
+ } else if (prop.type_reference.data_type == codegen.int_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_int");
+ cspec.add_argument (new CCodeConstant ("G_MININT"));
+ cspec.add_argument (new CCodeConstant ("G_MAXINT"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0"));
+ }
+ } else if (prop.type_reference.data_type == codegen.uint_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_uint");
+ cspec.add_argument (new CCodeConstant ("0"));
+ cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0U"));
+ }
+ } else if (prop.type_reference.data_type == codegen.long_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_long");
+ cspec.add_argument (new CCodeConstant ("G_MINLONG"));
+ cspec.add_argument (new CCodeConstant ("G_MAXLONG"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0L"));
+ }
+ } else if (prop.type_reference.data_type == codegen.ulong_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_ulong");
+ cspec.add_argument (new CCodeConstant ("0"));
+ cspec.add_argument (new CCodeConstant ("G_MAXULONG"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0UL"));
+ }
+ } else if (prop.type_reference.data_type == codegen.bool_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_boolean");
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("FALSE"));
+ }
+ } else if (prop.type_reference.data_type == codegen.float_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_float");
+ cspec.add_argument (new CCodeConstant ("-G_MAXFLOAT"));
+ cspec.add_argument (new CCodeConstant ("G_MAXFLOAT"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0.0F"));
+ }
+ } else if (prop.type_reference.data_type == codegen.double_type.data_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_double");
+ cspec.add_argument (new CCodeConstant ("-G_MAXDOUBLE"));
+ cspec.add_argument (new CCodeConstant ("G_MAXDOUBLE"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0.0"));
+ }
+ } else if (prop.type_reference.data_type == codegen.gtype_type) {
+ cspec.call = new CCodeIdentifier ("g_param_spec_gtype");
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("G_TYPE_NONE"));
+ }
+ } else {
+ cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
+ }
+
+ var pflags = "G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB";
+ if (prop.get_accessor != null) {
+ pflags = "%s%s".printf (pflags, " | G_PARAM_READABLE");
+ }
+ if (prop.set_accessor != null) {
+ pflags = "%s%s".printf (pflags, " | G_PARAM_WRITABLE");
+ if (prop.set_accessor.construction) {
+ if (prop.set_accessor.writable) {
+ pflags = "%s%s".printf (pflags, " | G_PARAM_CONSTRUCT");
+ } else {
+ pflags = "%s%s".printf (pflags, " | G_PARAM_CONSTRUCT_ONLY");
+ }
+ }
+ }
+ cspec.add_argument (new CCodeConstant (pflags));
+
+ return cspec;
+ }
+
+ public CCodeFunctionCall get_signal_creation (Signal sig, Typesymbol type) {
+ var csignew = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_new"));
+ csignew.add_argument (new CCodeConstant ("\"%s\"".printf (sig.name)));
+ csignew.add_argument (new CCodeIdentifier (type.get_upper_case_cname ("TYPE_")));
+ csignew.add_argument (new CCodeConstant ("G_SIGNAL_RUN_LAST"));
+ csignew.add_argument (new CCodeConstant ("0"));
+ csignew.add_argument (new CCodeConstant ("NULL"));
+ csignew.add_argument (new CCodeConstant ("NULL"));
+
+ string marshaller = codegen.get_signal_marshaller_function (sig);
+
+ var marshal_arg = new CCodeIdentifier (marshaller);
+ csignew.add_argument (marshal_arg);
+
+ var params = sig.get_parameters ();
+ var params_len = params.size;
+ if (sig.return_type is PointerType || sig.return_type.type_parameter != null) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ } else if (sig.return_type is ErrorType) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ } else if (sig.return_type.data_type == null) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_NONE"));
+ } else {
+ csignew.add_argument (new CCodeConstant (sig.return_type.data_type.get_type_id ()));
+ }
+ csignew.add_argument (new CCodeConstant ("%d".printf (params_len)));
+ foreach (FormalParameter param in params) {
+ if (param.type_reference is PointerType || param.type_reference.type_parameter != null || param.direction != ParameterDirection.IN) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ } else if (param.type_reference is ErrorType) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
+ } else {
+ csignew.add_argument (new CCodeConstant (param.type_reference.data_type.get_type_id ()));
+ }
+ }
+
+ marshal_arg.name = marshaller;
+
+ return csignew;
+ }
+}
Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala (original)
+++ trunk/vala/valaclass.vala Sat Apr 19 06:06:38 2008
@@ -696,5 +696,9 @@
}
}
}
+
+ public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+ return codegen.create_class_binding (this);
+ }
}
Modified: trunk/vala/valainterface.vala
==============================================================================
--- trunk/vala/valainterface.vala (original)
+++ trunk/vala/valainterface.vala Sat Apr 19 06:06:38 2008
@@ -486,4 +486,8 @@
}
}
}
+
+ public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+ return codegen.create_interface_binding (this);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]