Commit db23cad6 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

support implicit array length parameter support NoArrayLength attribute

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

	* vala/valacodegenerator.vala: support implicit array length parameter
	* vala/valainterfacewriter.vala, vala/valaformalparameter.vala,
	  vala/valamethod.vala: support NoArrayLength attribute
	* compiler/valacompiler.vala, vapi/atk.vala, vapi/cairo.vala,
	  vapi/gdk-2.0.vala, vapi/glib-2.0.vala, vapi/gtk+-2.0.vala,
	  vapi/pango.vala: add NoArrayLength attributes
	* tests/test-001.vala, tests/test-002.vala, tests/test-003.vala,
	  tests/test-004.vala, tests/test-005.vala, tests/test-006.vala,
	  tests/test-007.vala, tests/test-008.vala, tests/test-009.vala,
	  tests/test-010.vala, tests/test-011.vala, tests/test-012.vala,
	  tests/test-013.vala, tests/test-014.vala, tests/test-015.vala,
	  tests/test-016.vala, tests/test-017.vala, tests/test-018.vala,
	  tests/test-019.vala, tests/test-020.vala: remove argc parameter

svn path=/trunk/; revision=106
parent 4463002f
2006-08-18 Jürg Billeter <j@bitron.ch>
* vala/valacodegenerator.vala: support implicit array length parameter
* vala/valainterfacewriter.vala, vala/valaformalparameter.vala,
vala/valamethod.vala: support NoArrayLength attribute
* compiler/valacompiler.vala, vapi/atk.vala, vapi/cairo.vala,
vapi/gdk-2.0.vala, vapi/glib-2.0.vala, vapi/gtk+-2.0.vala,
vapi/pango.vala: add NoArrayLength attributes
* tests/test-001.vala, tests/test-002.vala, tests/test-003.vala,
tests/test-004.vala, tests/test-005.vala, tests/test-006.vala,
tests/test-007.vala, tests/test-008.vala, tests/test-009.vala,
tests/test-010.vala, tests/test-011.vala, tests/test-012.vala,
tests/test-013.vala, tests/test-014.vala, tests/test-015.vala,
tests/test-016.vala, tests/test-017.vala, tests/test-018.vala,
tests/test-019.vala, tests/test-020.vala: remove argc parameter
2006-08-18 Jürg Billeter <j@bitron.ch>
* vala/parser.y: remove read/write tokens
......
......@@ -209,6 +209,7 @@ class Vala.Compiler {
return quit ();
}
[NoArrayLength ()]
static int main (int argc, string[] argv) {
Error err = null;
......
using GLib;
namespace Maman {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Namespace Test\n");
return 0;
}
......
......@@ -2,7 +2,7 @@ using GLib;
namespace Maman {
class Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Class in Namespace Test\n");
return 0;
}
......
......@@ -4,7 +4,7 @@ class Maman.Bar {
}
class Maman.SubBar : Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Subtype Test\n");
return 0;
}
......
......@@ -7,7 +7,7 @@ class Maman.Bar {
}
class Maman.SubBar : Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Inheritance Test: 1");
var bar = new SubBar ();
......
......@@ -7,7 +7,7 @@ class Maman.Bar {
}
class Maman.SubBar : Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Static Inheritance Test: 1");
do_action ();
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("For Test: 1");
int i;
......
......@@ -11,7 +11,7 @@ class Maman.SubBar : Bar {
stdout.printf (" 2");
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Virtual Method Test: 1");
Bar bar = new SubBar ();
......
......@@ -20,7 +20,7 @@ class Maman.Bar : Foo {
private_field, private_static_field);
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Field Test: 1");
var bar = new Bar ();
......
......@@ -30,7 +30,7 @@ class Maman.Bar : Foo {
stdout.printf (" %d %d", public_base_property, public_property);
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Property Test: 1");
var bar = new Bar ();
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Assignment Test: 1");
int i;
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Binary Expression Test: 1");
stdout.printf (" %d", 1 + 1);
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Block Test: 1");
{
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Break Test: 1");
int i;
......
......@@ -7,7 +7,7 @@ class Maman.Bar {
return 2;
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Callback Test: 1");
ActionCallback cb = do_action;
......
......@@ -7,7 +7,7 @@ class Maman.Bar {
return cb (1);
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Lambda Test: 1");
stdout.printf (" %d", do_action (i => i * 2));
......
using GLib;
class Maman.Bar {
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Conditional Expression Test: 1");
stdout.printf (" %d", false ? -1 : 2);
......
......@@ -9,7 +9,7 @@ class Maman.Baz : Ibaz {
stdout.printf (" 2");
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Interface Test: 1");
Ibaz ibaz = new Baz ();
......
......@@ -39,7 +39,7 @@ class Maman.Bar {
stdout.printf (" 6");
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Signal Test: 1");
var bar = new Bar ();
......
......@@ -29,7 +29,7 @@ class Maman.Foo {
return counter++;
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Element access: 1");
var foo = new Foo ();
......
......@@ -44,7 +44,7 @@ class Maman.Foo {
return counter++;
}
static int main (int argc, string[] argv) {
static int main (string[] args) {
stdout.printf ("Switch statement: 1");
var foo = new Foo ();
......
......@@ -954,6 +954,10 @@ public class Vala.CodeGenerator : CodeVisitor {
}
return null;
}
private ref string! get_array_length_cname (string! array_cname, int dim) {
return "%s_length%d".printf (array_cname, dim);
}
public override void visit_end_method (Method! m) {
current_symbol = current_symbol.parent_symbol;
......@@ -989,6 +993,23 @@ public class Vala.CodeGenerator : CodeVisitor {
var params = m.get_parameters ();
foreach (FormalParameter param in params) {
if (!param.no_array_length && param.type_reference.data_type is Array) {
var arr = (Array) param.type_reference.data_type;
var length_ctype = "int";
if (param.type_reference.is_out) {
length_ctype = "int*";
}
for (int dim = 1; dim <= arr.rank; dim++) {
var cparam = new CCodeFormalParameter (get_array_length_cname (param.name, dim), length_ctype);
function.add_parameter (cparam);
if (vdeclarator != null) {
vdeclarator.add_parameter (cparam);
}
}
}
function.add_parameter ((CCodeFormalParameter) param.ccodenode);
if (vdeclarator != null) {
vdeclarator.add_parameter ((CCodeFormalParameter) param.ccodenode);
......@@ -2023,6 +2044,37 @@ public class Vala.CodeGenerator : CodeVisitor {
visit_expression (expr);
}
private ref CCodeExpression! get_array_length_cexpression (Expression! array_expr, int dim) {
bool is_out = false;
if (array_expr is UnaryExpression) {
var unary_expr = (UnaryExpression) array_expr;
if (unary_expr.operator == UnaryOperator.OUT) {
array_expr = unary_expr.inner;
is_out = true;
}
}
if (array_expr.symbol_reference != null &&
array_expr.symbol_reference.node is FormalParameter) {
var param = (FormalParameter) array_expr.symbol_reference.node;
if (!param.no_array_length) {
var length_expr = new CCodeIdentifier (get_array_length_cname (param.name, dim));
if (is_out) {
return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
} else {
return length_expr;
}
}
}
if (!is_out) {
return new CCodeConstant ("-1");
} else {
return new CCodeConstant ("NULL");
}
}
public override void visit_end_invocation_expression (InvocationExpression! expr) {
var ccall = new CCodeFunctionCall ((CCodeExpression) expr.call.ccodenode);
......@@ -2096,14 +2148,21 @@ public class Vala.CodeGenerator : CodeVisitor {
if (!param.ellipsis
&& param.type_reference.data_type != null
&& param.type_reference.data_type.is_reference_type ()
&& arg.static_type.data_type != null
&& param.type_reference.data_type != arg.static_type.data_type) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier (param.type_reference.data_type.get_upper_case_cname (null)));
ccall.add_argument (cexpr);
cexpr = ccall;
&& arg.static_type.data_type != null) {
if (!param.no_array_length && param.type_reference.data_type is Array) {
var arr = (Array) param.type_reference.data_type;
for (int dim = 1; dim <= arr.rank; dim++) {
ccall.add_argument (get_array_length_cexpression (arg, dim));
}
}
if (param.type_reference.data_type != arg.static_type.data_type) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier (param.type_reference.data_type.get_upper_case_cname (null)));
ccall.add_argument (cexpr);
cexpr = ccall;
}
}
}
ccall.add_argument (cexpr);
i++;
......@@ -2129,6 +2188,14 @@ public class Vala.CodeGenerator : CodeVisitor {
* parameter yet */
param.default_expression.accept (this);
if (!param.no_array_length && param.type_reference != null &&
param.type_reference.data_type is Array) {
var arr = (Array) param.type_reference.data_type;
for (int dim = 1; dim <= arr.rank; dim++) {
ccall.add_argument (get_array_length_cexpression (param.default_expression, dim));
}
}
ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
i++;
......
......@@ -48,6 +48,12 @@ public class Vala.FormalParameter : CodeNode, Invokable {
*/
public Expression default_expression { get; set; }
/**
* Specifies whether the array length should implicitly be passed
* if the parameter type is an array.
*/
public bool no_array_length { get; set; }
/**
* Creates a new formal parameter.
*
......
......@@ -355,6 +355,11 @@ public class Vala.InterfaceWriter : CodeVisitor {
return;
}
if (m.no_array_length) {
write_indent ();
write_string ("[NoArrayLength ()]");
}
write_indent ();
write_string ("public");
......
......@@ -112,10 +112,27 @@ public class Vala.Method : CodeNode, Invokable {
* Specifies the generated `this' parameter for instance methods.
*/
public FormalParameter this_parameter { get; set; }
/**
* Specifies whether the array length should implicitly be passed
* if the parameter type is an array.
*/
public bool no_array_length {
get {
return _no_array_length;
}
set {
_no_array_length = value;
foreach (FormalParameter param in parameters) {
param.no_array_length = value;
}
}
}
private bool _instance = true;
private List<FormalParameter> parameters;
private string cname;
private bool _no_array_length;
/**
* Creates a new method.
......@@ -137,6 +154,10 @@ public class Vala.Method : CodeNode, Invokable {
* @param param a formal parameter
*/
public void add_parameter (FormalParameter! param) {
if (no_array_length) {
param.no_array_length = true;
}
parameters.append (param);
}
......@@ -243,6 +264,8 @@ public class Vala.Method : CodeNode, Invokable {
instance_last = true;
} else if (a.name == "FloatingReference") {
return_type.floating_reference = true;
} else if (a.name == "NoArrayLength") {
no_array_length = true;
}
}
}
......
[CCode (cheader_filename = "packages/atk/atk.h")]
namespace Atk {
public class GObjectAccessible : Atk.Object {
[NoArrayLength ()]
public static Atk.Object for_object (GLib.Object obj);
[NoArrayLength ()]
public GLib.Object get_object ();
[NoArrayLength ()]
public GLib.Type get_type ();
}
public class Hyperlink : GLib.Object, Atk.Action {
[NoArrayLength ()]
public int get_end_index ();
[NoArrayLength ()]
public int get_n_anchors ();
[NoArrayLength ()]
public Atk.Object get_object (int i);
[NoArrayLength ()]
public int get_start_index ();
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public string get_uri (int i);
[NoArrayLength ()]
public bool is_inline ();
[NoArrayLength ()]
public bool is_selected_link ();
[NoArrayLength ()]
public bool is_valid ();
[NoAccessorMethod ()]
public weak bool selected_link { get; }
......@@ -24,36 +36,63 @@ namespace Atk {
public signal void link_activated ();
}
public class NoOpObject : Atk.Object, Atk.Component, Atk.Action, Atk.EditableText, Atk.Image, Atk.Selection, Atk.Table, Atk.Text, Atk.Hypertext, Atk.Value {
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public construct (GLib.Object obj);
}
public class NoOpObjectFactory : Atk.ObjectFactory {
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public construct ();
}
public class Object : GLib.Object {
[NoArrayLength ()]
public bool add_relationship (Atk.RelationType relationship, Atk.Object target);
[NoArrayLength ()]
public uint connect_property_change_handler (Atk.PropertyChangeHandler handler);
[NoArrayLength ()]
public GLib.SList get_attributes ();
[NoArrayLength ()]
public string get_description ();
[NoArrayLength ()]
public int get_index_in_parent ();
[NoArrayLength ()]
public Atk.Layer get_layer ();
[NoArrayLength ()]
public int get_mdi_zorder ();
[NoArrayLength ()]
public int get_n_accessible_children ();
[NoArrayLength ()]
public string get_name ();
[NoArrayLength ()]
public Atk.Object get_parent ();
[NoArrayLength ()]
public Atk.Role get_role ();
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public void initialize (pointer data);
[NoArrayLength ()]
public void notify_state_change (Atk.State state, bool value);
[NoArrayLength ()]
public Atk.Object ref_accessible_child (int i);
[NoArrayLength ()]
public Atk.RelationSet ref_relation_set ();
[NoArrayLength ()]
public Atk.StateSet ref_state_set ();
[NoArrayLength ()]
public void remove_property_change_handler (uint handler_id);
[NoArrayLength ()]
public bool remove_relationship (Atk.RelationType relationship, Atk.Object target);
[NoArrayLength ()]
public void set_description (string description);
[NoArrayLength ()]
public void set_name (string name);
[NoArrayLength ()]
public void set_parent (Atk.Object parent);
[NoArrayLength ()]
public void set_role (Atk.Role role);
[NoAccessorMethod ()]
public weak string atk_object_name_property_name { get; set; }
......@@ -93,25 +132,41 @@ namespace Atk {
public signal void active_descendant_changed (pointer child);
}
public class ObjectFactory : GLib.Object {
[NoArrayLength ()]
public Atk.Object create_accessible (GLib.Object obj);
[NoArrayLength ()]
public GLib.Type get_accessible_type ();
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public void invalidate ();
}
public class Registry : GLib.Object {
[NoArrayLength ()]
public Atk.ObjectFactory get_factory (GLib.Type type);
[NoArrayLength ()]
public GLib.Type get_factory_type (GLib.Type type);
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public void set_factory_type (GLib.Type type, GLib.Type factory_type);
}
public class Relation : GLib.Object {
[NoArrayLength ()]
public void add_target (Atk.Object target);
[NoArrayLength ()]
public Atk.RelationType get_relation_type ();
[NoArrayLength ()]
public GLib.PtrArray get_target ();
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public construct (Atk.Object targets, int n_targets, Atk.RelationType relationship);
[NoArrayLength ()]
public static Atk.RelationType type_for_name (string name);
[NoArrayLength ()]
public static string type_get_name (Atk.RelationType type);
[NoArrayLength ()]
public static Atk.RelationType type_register (string name);
[NoAccessorMethod ()]
public weak Atk.RelationType relation_type { get; set; }
......@@ -119,189 +174,338 @@ namespace Atk {
public weak GLib.ValueArray target { get; set; }
}
public class RelationSet : GLib.Object {
[NoArrayLength ()]
public void add (Atk.Relation relation);
[NoArrayLength ()]
public void add_relation_by_type (Atk.RelationType relationship, Atk.Object target);
[NoArrayLength ()]
public bool contains (Atk.RelationType relationship);
[NoArrayLength ()]
public int get_n_relations ();
[NoArrayLength ()]
public Atk.Relation get_relation (int i);
[NoArrayLength ()]
public Atk.Relation get_relation_by_type (Atk.RelationType relationship);
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public construct ();
[NoArrayLength ()]
public void remove (Atk.Relation relation);
}
public class StateSet : GLib.Object {
[NoArrayLength ()]
public bool add_state (Atk.StateType type);
[NoArrayLength ()]
public void add_states (Atk.StateType types, int n_types);
[NoArrayLength ()]
public Atk.StateSet and_sets (Atk.StateSet compare_set);
[NoArrayLength ()]
public void clear_states ();
[NoArrayLength ()]
public bool contains_state (Atk.StateType type);
[NoArrayLength ()]
public bool contains_states (Atk.StateType types, int n_types);
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public bool is_empty ();
[NoArrayLength ()]
public construct ();
[NoArrayLength ()]
public Atk.StateSet or_sets (Atk.StateSet compare_set);
[NoArrayLength ()]
public bool remove_state (Atk.StateType type);
[NoArrayLength ()]
public Atk.StateSet xor_sets (Atk.StateSet compare_set);
}
public class Util : GLib.Object {
[NoArrayLength ()]
public GLib.Type get_type ();
}
public interface Action {
[NoArrayLength ()]
public bool do_action (int i);
[NoArrayLength ()]
public string get_description (int i);
[NoArrayLength ()]
public string get_keybinding (int i);
[NoArrayLength ()]
public string get_localized_name (int i);
[NoArrayLength ()]
public int get_n_actions ();
[NoArrayLength ()]
public string get_name (int i);
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public bool set_description (int i, string desc);
}
public interface Component {
[NoArrayLength ()]
public uint add_focus_handler (Atk.FocusHandler handler);
[NoArrayLength ()]
public bool contains (int x, int y, Atk.CoordType coord_type);
[NoArrayLength ()]
public double get_alpha ();
[NoArrayLength ()]
public void get_extents (int x, int y, int width, int height, Atk.CoordType coord_type);
[NoArrayLength ()]
public Atk.Layer get_layer ();
[NoArrayLength ()]
public int get_mdi_zorder ();
[NoArrayLength ()]
public void get_position (int x, int y, Atk.CoordType coord_type);
[NoArrayLength ()]
public void get_size (int width, int height);
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public bool grab_focus ();
[NoArrayLength ()]
public Atk.Object ref_accessible_at_point (int x, int y, Atk.CoordType coord_type);
[NoArrayLength ()]
public void remove_focus_handler (uint handler_id);
[NoArrayLength ()]
public bool set_extents (int x, int y, int width, int height, Atk.CoordType coord_type);
[NoArrayLength ()]
public bool set_position (int x, int y, Atk.CoordType coord_type);
[NoArrayLength ()]
public bool set_size (int width, int height);
}
public interface Document {
[NoArrayLength ()]
public string get_attribute_value (string attribute_name);
[NoArrayLength ()]
public GLib.SList get_attributes ();
[NoArrayLength ()]
public pointer get_document ();
[NoArrayLength ()]
public string get_document_type ();
[NoArrayLength ()]
public string get_locale ();
[NoArrayLength ()]
public GLib.Type get_type ();
[NoArrayLength ()]
public bool set_attribute_value (string attribute_name, string attribute_value);
}
public interface EditableText {
[NoArrayLength ()]
public void copy_text (int start_pos, int end_pos);
[NoArrayLength ()]
public void cut_text (int start_pos, int end_pos);
[NoArrayLength ()]