From: Juerg Billeter Date: Wed, 9 Jan 2008 23:13:12 +0000 (+0000) Subject: check in/ref/out arguments X-Git-Tag: VALA_0_1_6~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fefc186f24e2f26eb50619352df79b564c29a014;p=thirdparty%2Fvala.git check in/ref/out arguments 2008-01-10 Juerg Billeter * vala/valasemanticanalyzer.vala: check in/ref/out arguments * vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala: fix gtk_init * vapi/gtk+-2.0.vapi: regenerated svn path=/trunk/; revision=821 --- diff --git a/ChangeLog b/ChangeLog index 91d185d44..5a94cca9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-01-10 Jürg Billeter + + * vala/valasemanticanalyzer.vala: check in/ref/out arguments + + * vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala: fix gtk_init + + * vapi/gtk+-2.0.vapi: regenerated + 2008-01-09 Jürg Billeter * vapi/glib-2.0.vapi: add bindings for uri functions diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index b7a162cc6..4dc60ae61 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -1545,6 +1545,45 @@ public class Vala.SemanticAnalyzer : CodeVisitor { expr.error = true; Report.error (expr.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.to_string (), param.type_reference.to_string ())); return false; + } else { + // 0 => null, 1 => in, 2 => ref, 3 => out + int arg_type = 1; + if (arg.static_type is NullType) { + arg_type = 0; + } else if (arg is UnaryExpression) { + var unary = (UnaryExpression) arg; + if (unary.operator == UnaryOperator.REF) { + arg_type = 2; + } else if (unary.operator == UnaryOperator.OUT) { + arg_type = 3; + } + } + + if (arg_type == 0) { + if (param.type_reference.is_ref) { + expr.error = true; + Report.error (expr.source_reference, "Argument %d: Cannot pass null to reference parameter".printf (i + 1)); + return false; + } + } else if (arg_type == 1) { + if (param.type_reference.is_ref || param.type_reference.is_out) { + expr.error = true; + Report.error (expr.source_reference, "Argument %d: Cannot pass value to reference or output parameter".printf (i + 1)); + return false; + } + } else if (arg_type == 2) { + if (!param.type_reference.is_ref) { + expr.error = true; + Report.error (expr.source_reference, "Argument %d: Cannot pass ref argument to non-reference parameter".printf (i + 1)); + return false; + } + } else if (arg_type == 3) { + if (!param.type_reference.is_out) { + expr.error = true; + Report.error (expr.source_reference, "Argument %d: Cannot pass out argument to non-output parameter".printf (i + 1)); + return false; + } + } } prev_arg = arg; diff --git a/vapi/gtk+-2.0.vapi b/vapi/gtk+-2.0.vapi index ed9de0125..a92173916 100644 --- a/vapi/gtk+-2.0.vapi +++ b/vapi/gtk+-2.0.vapi @@ -6356,7 +6356,7 @@ namespace Gtk { public const string STOCK_ZOOM_OUT; public const int TEXT_VIEW_PRIORITY_VALIDATE; public const int TYPE_FUNDAMENTAL_LAST; - public static void init (out string[] args); + public static void init (ref string[] args); public static bool accel_groups_activate (GLib.Object object, uint accel_key, Gdk.ModifierType accel_mods); public static weak GLib.SList accel_groups_from_object (GLib.Object object); public static uint accelerator_get_default_mod_mask (); diff --git a/vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala b/vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala index c0fce51c2..dbcedbde8 100644 --- a/vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala +++ b/vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala @@ -1,6 +1,6 @@ /* gtk+-2.0.vala * - * Copyright (C) 2006-2007 Jürg Billeter + * Copyright (C) 2006-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 @@ -22,7 +22,7 @@ namespace Gtk { [Import] - public void init (out string[] args); + public void init (ref string[] args); public struct Allocation { public int x;