2007-07-24 Jürg Billeter <j@bitron.ch>
+ * gobject/valacodegenerator.vala,
+ gobject/valacodegeneratormemberaccess.vala,
+ gobject/valacodegeneratormethod.vala: remove unnecessary runtime
+ checks in release mode, simplify creation method when not using
+ construction properties
+
+2007-07-24 Jürg Billeter <j@bitron.ch>
+
* vala/parser.y, vala/valainterface.vala: allow private static fields in
interfaces, fixes bug 437435
public override void visit_begin_block (Block! b) {
current_symbol = b;
}
-
- private void add_object_creation (CCodeBlock! b) {
+
+ private void add_object_creation (CCodeBlock! b, bool has_params) {
var cl = (Class) current_type_symbol;
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
ccall.add_argument (new CCodeConstant (cl.get_type_id ()));
- ccall.add_argument (new CCodeConstant ("__params_it - __params"));
- ccall.add_argument (new CCodeConstant ("__params"));
+ if (has_params) {
+ ccall.add_argument (new CCodeConstant ("__params_it - __params"));
+ ccall.add_argument (new CCodeConstant ("__params"));
+ } else {
+ ccall.add_argument (new CCodeConstant ("0"));
+ ccall.add_argument (new CCodeConstant ("NULL"));
+ }
var cdecl = new CCodeVariableDeclarator ("self");
cdecl.initializer = ccall;
if (f.instance) {
CCodeExpression typed_inst;
if (f.parent_symbol != base_type) {
- // FIXME: use C cast if debugging disabled
- typed_inst = new CCodeFunctionCall (new CCodeIdentifier (((DataType) f.parent_symbol).get_upper_case_cname (null)));
- ((CCodeFunctionCall) typed_inst).add_argument (pub_inst);
+ if (context.debug) {
+ typed_inst = new CCodeFunctionCall (new CCodeIdentifier (((DataType) f.parent_symbol).get_upper_case_cname (null)));
+ ((CCodeFunctionCall) typed_inst).add_argument (pub_inst);
+ } else {
+ typed_inst = new CCodeCastExpression (pub_inst, ((DataType) f.parent_symbol).get_cname () + "*");
+ }
} else {
typed_inst = pub_inst;
}
/* cast if necessary */
if (base_property_type != base_type) {
- // FIXME: use C cast if debugging disabled
- var ccast = new CCodeFunctionCall (new CCodeIdentifier (base_property_type.get_upper_case_cname (null)));
- ccast.add_argument (pub_inst);
- typed_pub_inst = ccast;
+ if (context.debug) {
+ var ccast = new CCodeFunctionCall (new CCodeIdentifier (base_property_type.get_upper_case_cname (null)));
+ ccast.add_argument (pub_inst);
+ typed_pub_inst = ccast;
+ } else {
+ typed_pub_inst = new CCodeCastExpression (pub_inst, base_property_type.get_cname () + "*");
+ }
}
ccall.add_argument (typed_pub_inst);
}
}
- add_object_creation (cblock);
+ add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0);
foreach (CodeNode stmt in m.body.get_statements ()) {
if (!((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
if (m.parent_symbol is Class) {
var cl = (Class) m.parent_symbol;
if (m.overrides || m.base_interface_method != null) {
- var ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_upper_case_cname (null)));
- ccall.add_argument (new CCodeIdentifier ("base"));
+ CCodeExpression cself;
+ if (context.debug) {
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_upper_case_cname (null)));
+ ccall.add_argument (new CCodeIdentifier ("base"));
+ cself = ccall;
+ } else {
+ cself = new CCodeCastExpression (new CCodeIdentifier ("base"), cl.get_cname () + "*");
+ }
var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
- cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall));
+ cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", cself));
cinit.append (cdecl);
} else if (m.instance) {
if (m is CreationMethod) {
if (current_type_symbol is Class) {
int n_params = ((CreationMethod) m).n_construction_params;
- n_params += (int) current_class.get_type_parameters ().length ();
- // declare construction parameter array
- var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
- cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
- cparamsinit.add_argument (new CCodeConstant (n_params.to_string ()));
-
- var cdecl = new CCodeDeclaration ("GParameter *");
- cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("__params", cparamsinit));
- cinit.append (cdecl);
-
- cdecl = new CCodeDeclaration ("GParameter *");
- cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("__params_it", new CCodeIdentifier ("__params")));
- cinit.append (cdecl);
+ if (n_params > 0) {
+ // declare construction parameter array
+ var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
+ cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
+ cparamsinit.add_argument (new CCodeConstant (n_params.to_string ()));
+
+ var cdecl = new CCodeDeclaration ("GParameter *");
+ cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("__params", cparamsinit));
+ cinit.append (cdecl);
+
+ cdecl = new CCodeDeclaration ("GParameter *");
+ cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("__params_it", new CCodeIdentifier ("__params")));
+ cinit.append (cdecl);
+ }
/* destroy func properties for generic types */
foreach (TypeParameter type_param in current_class.get_type_parameters ()) {