vala r1237 - in trunk: . gobject vala vapigen
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1237 - in trunk: . gobject vala vapigen
- Date: Tue, 15 Apr 2008 21:07:20 +0100 (BST)
Author: juergbi
Date: Tue Apr 15 21:07:19 2008
New Revision: 1237
URL: http://svn.gnome.org/viewvc/vala?rev=1237&view=rev
Log:
2008-04-15 Juerg Billeter <j bitron ch>
* vala/valaarraytype.vala, vala/valaclasstype.vala,
vala/valadatatype.vala, vala/valaformalparameter.vala,
vala/valainterfacetype.vala, vala/valainterfacewriter.vala,
vala/valanulltype.vala, vala/valaparser.vala,
vala/valasemanticanalyzer.vala, vala/valasymbolresolver.vala,
vala/valatypeparametertype.vala, vala/valaunresolvedtype.vala,
vala/valavaluetype.vala, gobject/valaccodegenerator.vala,
gobject/valaccodegeneratorinterface.vala,
gobject/valaccodegeneratorinvocationexpression.vala,
gobject/valaccodegeneratormemberaccess.vala,
gobject/valaccodegeneratormethod.vala,
gobject/valaccodegeneratorsignal.vala,
gobject/valagidlwriter.vala, vapigen/valagidlparser.vala:
Remove is_ref and is_out properties from DataType class, add
direction property to FormalParameter class
Modified:
trunk/ChangeLog
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valaccodegeneratorinterface.vala
trunk/gobject/valaccodegeneratorinvocationexpression.vala
trunk/gobject/valaccodegeneratormemberaccess.vala
trunk/gobject/valaccodegeneratormethod.vala
trunk/gobject/valaccodegeneratorsignal.vala
trunk/gobject/valagidlwriter.vala
trunk/vala/valaarraytype.vala
trunk/vala/valaclasstype.vala
trunk/vala/valadatatype.vala
trunk/vala/valaformalparameter.vala
trunk/vala/valainterfacetype.vala
trunk/vala/valainterfacewriter.vala
trunk/vala/valanulltype.vala
trunk/vala/valaparser.vala
trunk/vala/valasemanticanalyzer.vala
trunk/vala/valasymbolresolver.vala
trunk/vala/valatypeparametertype.vala
trunk/vala/valaunresolvedtype.vala
trunk/vala/valavaluetype.vala
trunk/vapigen/valagidlparser.vala
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Tue Apr 15 21:07:19 2008
@@ -695,11 +695,15 @@
// pass non-simple structs always by reference
if (p.type_reference.data_type is Struct) {
var st = (Struct) p.type_reference.data_type;
- if (!st.is_simple_type () && !p.type_reference.is_ref && !p.type_reference.is_out && !p.type_reference.nullable) {
+ if (!st.is_simple_type () && p.direction == ParameterDirection.IN && !p.type_reference.nullable) {
ctypename += "*";
}
}
+ if (p.direction != ParameterDirection.IN) {
+ ctypename += "*";
+ }
+
p.ccodenode = new CCodeFormalParameter (cname, ctypename);
} else {
p.ccodenode = new CCodeFormalParameter.with_ellipsis ();
@@ -1025,7 +1029,7 @@
if (b.parent_symbol is Method) {
var m = (Method) b.parent_symbol;
foreach (FormalParameter param in m.get_parameters ()) {
- if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
+ if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && param.direction == ParameterDirection.IN) {
var ma = new MemberAccess.simple (param.name);
ma.symbol_reference = param;
cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (param.name)), param.type_reference, ma)));
@@ -1174,8 +1178,6 @@
public VariableDeclarator get_temp_variable_declarator (DataType type, bool takes_ownership = true, CodeNode? node_reference = null) {
var decl = new VariableDeclarator ("_tmp%d".printf (next_temp_var_id));
decl.type_reference = type.copy ();
- decl.type_reference.is_ref = false;
- decl.type_reference.is_out = false;
decl.type_reference.takes_ownership = takes_ownership;
if (node_reference != null) {
@@ -1760,8 +1762,6 @@
var collection_backup = stmt.collection_variable_declarator;
var collection_type = collection_backup.type_reference.copy ();
- collection_type.is_ref = false;
- collection_type.is_out = false;
var ccoldecl = new CCodeDeclaration (collection_type.get_cname ());
var ccolvardecl = new CCodeVariableDeclarator.with_initializer (collection_backup.name, (CCodeExpression) stmt.collection.ccodenode);
ccolvardecl.line = cblock.line;
@@ -2043,7 +2043,7 @@
private void append_param_free (Method m, CCodeFragment cfrag) {
foreach (FormalParameter param in m.get_parameters ()) {
- if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
+ if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && param.direction == ParameterDirection.IN) {
var ma = new MemberAccess.simple (param.name);
ma.symbol_reference = param;
cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (param.name)), param.type_reference, ma)));
@@ -2088,7 +2088,7 @@
bool found = false;
foreach (FormalParameter param in m.get_parameters ()) {
- if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && !param.type_reference.is_ref && !param.type_reference.is_out) {
+ if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && param.type_reference.takes_ownership && param.direction == ParameterDirection.IN) {
found = true;
var ma = new MemberAccess.simple (param.name);
ma.symbol_reference = param;
@@ -2418,7 +2418,7 @@
var param = (FormalParameter) array_expr.symbol_reference;
if (!param.no_array_length) {
CCodeExpression length_expr = new CCodeIdentifier (get_array_length_cname (param.name, dim));
- if (param.type_reference.is_out || param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
// accessing argument of out/ref param
length_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, length_expr));
}
@@ -2539,7 +2539,7 @@
if (delegate_expr.symbol_reference is FormalParameter) {
var param = (FormalParameter) delegate_expr.symbol_reference;
CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (param.name));
- if (param.type_reference.is_out || param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
// accessing argument of out/ref param
target_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr));
}
@@ -2881,7 +2881,7 @@
// pass non-simple struct instances always by reference
if (param.type_reference.data_type is Struct && !((Struct) param.type_reference.data_type).is_simple_type ()) {
// we already use a reference for arguments of ref and out parameters
- if (!param.type_reference.is_ref && !param.type_reference.is_out) {
+ if (param.direction == ParameterDirection.IN) {
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
}
}
@@ -3320,7 +3320,7 @@
var array_type = (ArrayType) param.type_reference;
var length_ctype = "int";
- if (param.type_reference.is_out || param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
length_ctype = "int*";
}
Modified: trunk/gobject/valaccodegeneratorinterface.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinterface.vala (original)
+++ trunk/gobject/valaccodegeneratorinterface.vala Tue Apr 15 21:07:19 2008
@@ -248,7 +248,7 @@
}
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.type_reference.is_ref || param.type_reference.is_out) {
+ 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"));
Modified: trunk/gobject/valaccodegeneratorinvocationexpression.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinvocationexpression.vala (original)
+++ trunk/gobject/valaccodegeneratorinvocationexpression.vala Tue Apr 15 21:07:19 2008
@@ -254,7 +254,7 @@
// pass non-simple struct instances always by reference
if (!(arg.static_type is NullType) && param.type_reference.data_type is Struct && !((Struct) param.type_reference.data_type).is_simple_type ()) {
// we already use a reference for arguments of ref and out parameters
- if (!param.type_reference.is_ref && !param.type_reference.is_out) {
+ if (param.direction == ParameterDirection.IN) {
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
}
}
@@ -279,7 +279,7 @@
}
// unref old value for non-null non-weak out arguments
- if (param.type_reference.is_out && param.type_reference.takes_ownership && !(arg.static_type is NullType)) {
+ if (param.direction == ParameterDirection.OUT && param.type_reference.takes_ownership && !(arg.static_type is NullType)) {
var unary = (UnaryExpression) arg;
// (ret_tmp = call (&tmp), free (var1), var1 = tmp, ret_tmp)
Modified: trunk/gobject/valaccodegeneratormemberaccess.vala
==============================================================================
--- trunk/gobject/valaccodegeneratormemberaccess.vala (original)
+++ trunk/gobject/valaccodegeneratormemberaccess.vala Tue Apr 15 21:07:19 2008
@@ -179,8 +179,7 @@
expr.ccodenode = pub_inst;
} else {
var type_as_struct = p.type_reference.data_type as Struct;
- if (p.type_reference.is_out
- || p.type_reference.is_ref
+ if (p.direction != ParameterDirection.IN
|| (type_as_struct != null && !type_as_struct.is_simple_type ())) {
expr.ccodenode = new CCodeIdentifier ("(*%s)".printf (p.name));
} else {
Modified: trunk/gobject/valaccodegeneratormethod.vala
==============================================================================
--- trunk/gobject/valaccodegeneratormethod.vala (original)
+++ trunk/gobject/valaccodegeneratormethod.vala Tue Apr 15 21:07:19 2008
@@ -179,7 +179,7 @@
var array_type = (ArrayType) param.type_reference;
var length_ctype = "int";
- if (param.type_reference.is_out || param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
length_ctype = "int*";
}
@@ -301,7 +301,7 @@
var t = param.type_reference.data_type;
if (t != null && t.is_reference_type ()) {
- if (!param.type_reference.is_out) {
+ if (param.direction != ParameterDirection.OUT) {
var type_check = create_method_type_check_statement (m, creturn_type, t, (context.non_null && !param.type_reference.nullable), param.name);
if (type_check != null) {
type_check.line = function.line;
@@ -459,7 +459,7 @@
var array_type = (ArrayType) param.type_reference;
var length_ctype = "int";
- if (param.type_reference.is_out || param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
length_ctype = "int*";
}
@@ -801,7 +801,7 @@
params_it.next ();
var param = params_it.get ();
- if (param.type_reference.is_out) {
+ if (param.direction == ParameterDirection.OUT) {
// parameter must not be an out parameter
return false;
}
Modified: trunk/gobject/valaccodegeneratorsignal.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorsignal.vala (original)
+++ trunk/gobject/valaccodegeneratorsignal.vala Tue Apr 15 21:07:19 2008
@@ -25,7 +25,7 @@
public class Vala.CCodeGenerator {
private string get_marshaller_type_name (DataType t) {
- if (t is PointerType || t.type_parameter != null || t.is_ref || t.is_out) {
+ if (t is PointerType || t.type_parameter != null) {
return ("POINTER");
} else if (t is ErrorType) {
return ("POINTER");
@@ -36,6 +36,14 @@
}
}
+ private string get_marshaller_type_name_for_parameter (FormalParameter param) {
+ if (param.direction != ParameterDirection.IN) {
+ return ("POINTER");
+ } else {
+ return get_marshaller_type_name (param.type_reference);
+ }
+ }
+
public string get_signal_marshaller_function (Signal sig, string? prefix = null) {
var signature = get_signal_signature (sig);
string ret;
@@ -55,7 +63,7 @@
ret = ret + "_VOID";
} else {
foreach (FormalParameter p in params) {
- ret = "%s_%s".printf (ret, get_marshaller_type_name (p.type_reference));
+ ret = "%s_%s".printf (ret, get_marshaller_type_name_for_parameter (p));
}
}
@@ -63,7 +71,7 @@
}
private string? get_value_type_name_from_type_reference (DataType t) {
- if (t is PointerType || t.type_parameter != null || t.is_ref || t.is_out) {
+ if (t is PointerType || t.type_parameter != null) {
return "gpointer";
} else if (t is VoidType) {
return "void";
@@ -89,6 +97,14 @@
return null;
}
+ private string? get_value_type_name_from_parameter (FormalParameter p) {
+ if (p.direction != ParameterDirection.IN) {
+ return "gpointer";
+ } else {
+ return get_value_type_name_from_type_reference (p.type_reference);
+ }
+ }
+
private string get_signal_signature (Signal sig) {
string signature;
var params = sig.get_parameters ();
@@ -100,10 +116,10 @@
bool first = true;
foreach (FormalParameter p in params) {
if (first) {
- signature = signature + get_marshaller_type_name (p.type_reference);
+ signature = signature + get_marshaller_type_name_for_parameter (p);
first = false;
} else {
- signature = "%s,%s".printf (signature, get_marshaller_type_name (p.type_reference));
+ signature = "%s,%s".printf (signature, get_marshaller_type_name_for_parameter (p));
}
}
}
@@ -152,7 +168,7 @@
callback_decl.add_parameter (new CCodeFormalParameter ("data1", "gpointer"));
n_params = 1;
foreach (FormalParameter p in params) {
- callback_decl.add_parameter (new CCodeFormalParameter ("arg_%d".printf (n_params), get_value_type_name_from_type_reference (p.type_reference)));
+ callback_decl.add_parameter (new CCodeFormalParameter ("arg_%d".printf (n_params), get_value_type_name_from_parameter (p)));
n_params++;
}
callback_decl.add_parameter (new CCodeFormalParameter ("data2", "gpointer"));
@@ -210,7 +226,7 @@
i = 1;
foreach (FormalParameter p in params) {
string get_value_function;
- if (p.type_reference is PointerType || p.type_reference.type_parameter != null || p.type_reference.is_ref || p.type_reference.is_out) {
+ if (p.type_reference is PointerType || p.type_reference.type_parameter != null || p.direction != ParameterDirection.IN) {
get_value_function = "g_value_get_pointer";
} else if (p.type_reference is ErrorType) {
get_value_function = "g_value_get_pointer";
Modified: trunk/gobject/valagidlwriter.vala
==============================================================================
--- trunk/gobject/valagidlwriter.vala (original)
+++ trunk/gobject/valagidlwriter.vala Tue Apr 15 21:07:19 2008
@@ -320,13 +320,13 @@
foreach (FormalParameter param in params) {
write_indent ();
stream.printf ("<parameter name=\"%s\" type=\"%s\"", param.name, get_gidl_type_name (param.type_reference));
- if (param.type_reference.is_ref) {
+ if (param.direction == ParameterDirection.REF) {
stream.printf (" direction=\"inout\"");
// in/out paramter
if (param.type_reference.takes_ownership) {
stream.printf (" transfer=\"full\"");
}
- } else if (param.type_reference.is_out) {
+ } else if (param.direction == ParameterDirection.OUT) {
// out paramter
stream.printf (" direction=\"out\"");
if (param.type_reference.takes_ownership) {
Modified: trunk/vala/valaarraytype.vala
==============================================================================
--- trunk/vala/valaarraytype.vala (original)
+++ trunk/vala/valaarraytype.vala Tue Apr 15 21:07:19 2008
@@ -119,10 +119,8 @@
var result = new ArrayType (element_type, rank, source_reference);
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.floating_reference = floating_reference;
- result.is_ref = is_ref;
foreach (DataType arg in get_type_arguments ()) {
result.add_type_argument (arg.copy ());
Modified: trunk/vala/valaclasstype.vala
==============================================================================
--- trunk/vala/valaclasstype.vala (original)
+++ trunk/vala/valaclasstype.vala Tue Apr 15 21:07:19 2008
@@ -41,10 +41,8 @@
result.source_reference = source_reference;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.floating_reference = floating_reference;
- result.is_ref = is_ref;
foreach (DataType arg in get_type_arguments ()) {
result.add_type_argument (arg.copy ());
Modified: trunk/vala/valadatatype.vala
==============================================================================
--- trunk/vala/valadatatype.vala (original)
+++ trunk/vala/valadatatype.vala Tue Apr 15 21:07:19 2008
@@ -41,11 +41,6 @@
public bool takes_ownership { get; set; }
/**
- * Specifies that the expression is a reference used in out parameters.
- */
- public bool is_out { get; set; }
-
- /**
* Specifies that the expression may be null.
*/
public bool nullable { get; set; }
@@ -65,11 +60,6 @@
*/
public bool floating_reference { get; set; }
- /**
- * Specifies that the expression is a reference used in ref parameters.
- */
- public bool is_ref { get; set; }
-
private Gee.List<DataType> type_argument_list = new ArrayList<DataType> ();
/**
@@ -123,12 +113,10 @@
}
string ptr;
- if (type_parameter != null || (!data_type.is_reference_type () && !is_ref && !is_out)) {
+ if (type_parameter != null || !data_type.is_reference_type ()) {
ptr = "";
- } else if ((data_type.is_reference_type () && !is_ref && !is_out) || (!data_type.is_reference_type () && (is_ref || is_out))) {
- ptr = "*";
} else {
- ptr = "**";
+ ptr = "*";
}
if (data_type != null) {
return data_type.get_cname (const_type) + ptr;
@@ -242,12 +230,6 @@
if (type2.takes_ownership != takes_ownership) {
return false;
}
- if (type2.is_ref != is_ref) {
- return false;
- }
- if (type2.is_out != is_out) {
- return false;
- }
if (type2.nullable != nullable) {
return false;
}
@@ -283,12 +265,6 @@
if (type2.takes_ownership != takes_ownership) {
return false;
}
- if (type2.is_ref != is_ref) {
- return false;
- }
- if (type2.is_out != is_out) {
- return false;
- }
if (!type2.nullable && nullable) {
return false;
Modified: trunk/vala/valaformalparameter.vala
==============================================================================
--- trunk/vala/valaformalparameter.vala (original)
+++ trunk/vala/valaformalparameter.vala Tue Apr 15 21:07:19 2008
@@ -38,7 +38,9 @@
_data_type.parent_node = this;
}
}
-
+
+ public ParameterDirection direction { get; set; default = ParameterDirection.IN; }
+
/**
* Specifies whether the methods accepts an indefinite number of
* parameters.
@@ -158,3 +160,10 @@
}
}
}
+
+public enum Vala.ParameterDirection {
+ IN,
+ OUT,
+ REF
+}
+
Modified: trunk/vala/valainterfacetype.vala
==============================================================================
--- trunk/vala/valainterfacetype.vala (original)
+++ trunk/vala/valainterfacetype.vala Tue Apr 15 21:07:19 2008
@@ -41,10 +41,8 @@
result.source_reference = source_reference;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.floating_reference = floating_reference;
- result.is_ref = is_ref;
foreach (DataType arg in get_type_arguments ()) {
result.add_type_argument (arg.copy ());
Modified: trunk/vala/valainterfacewriter.vala
==============================================================================
--- trunk/vala/valainterfacewriter.vala (original)
+++ trunk/vala/valainterfacewriter.vala Tue Apr 15 21:07:19 2008
@@ -510,10 +510,10 @@
write_string ("[CCode (%s)] ".printf (ccode_params.str));
}
- if (param.type_reference.is_ref || param.type_reference.is_out) {
- if (param.type_reference.is_ref) {
+ if (param.direction != ParameterDirection.IN) {
+ if (param.direction == ParameterDirection.REF) {
write_string ("ref ");
- } else if (param.type_reference.is_out) {
+ } else if (param.direction == ParameterDirection.OUT) {
write_string ("out ");
}
if (param.type_reference.data_type != null && param.type_reference.data_type.is_reference_type () && !param.type_reference.takes_ownership) {
Modified: trunk/vala/valanulltype.vala
==============================================================================
--- trunk/vala/valanulltype.vala (original)
+++ trunk/vala/valanulltype.vala Tue Apr 15 21:07:19 2008
@@ -38,7 +38,6 @@
/* null can be cast to any reference or array type or pointer type */
if (target_type.type_parameter != null ||
target_type is PointerType ||
- target_type.is_out ||
target_type.nullable ||
target_type.data_type.get_attribute ("PointerType") != null) {
return true;
Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala (original)
+++ trunk/vala/valaparser.vala Tue Apr 15 21:07:19 2008
@@ -341,9 +341,6 @@
return type;
}
- bool is_ref = accept (TokenType.REF);
- bool is_out = !is_ref && accept (TokenType.OUT);
-
bool is_weak = accept (TokenType.WEAK);
var sym = parse_symbol_name ();
@@ -384,8 +381,6 @@
type.add_type_argument (type_arg);
}
}
- type.is_ref = is_ref;
- type.is_out = is_out;
type.is_weak = is_weak;
type.pointer_level = stars;
type.array_rank = array_rank;
@@ -2526,13 +2521,20 @@
Report.warning (get_last_src (), "deprecated syntax, use assignments in the method body");
construct_param = true;
}
+ var direction = ParameterDirection.IN;
+ if (accept (TokenType.OUT)) {
+ direction = ParameterDirection.OUT;
+ } else if (accept (TokenType.REF)) {
+ direction = ParameterDirection.REF;
+ }
+
var type = parse_type ();
var ut = type as UnresolvedType;
if (ut != null) {
if (!ut.is_weak) {
ut.takes_ownership = true;
}
- if (!ut.is_ref && !ut.is_out && !ut.transfers_ownership) {
+ if (direction == ParameterDirection.IN && !ut.transfers_ownership) {
// take_ownership for in parameters that don't transfer ownership is not supported
ut.takes_ownership = false;
}
@@ -2540,6 +2542,7 @@
string id = parse_identifier ();
var param = context.create_formal_parameter (id, type, get_src (begin));
set_attributes (param, attrs);
+ param.direction = direction;
param.construct_parameter = construct_param;
if (accept (TokenType.ASSIGN)) {
param.default_expression = parse_expression ();
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Tue Apr 15 21:07:19 2008
@@ -536,7 +536,7 @@
if (p.default_expression != null) {
if (p.default_expression is NullLiteral
&& !p.type_reference.nullable
- && !p.type_reference.is_out) {
+ && p.direction != ParameterDirection.OUT) {
p.error = true;
Report.error (p.source_reference, "`null' incompatible with parameter type `%s`".printf (p.type_reference.to_string ()));
return;
@@ -1825,7 +1825,8 @@
Report.error (arg.source_reference, "Invalid type for argument %d".printf (i + 1));
return false;
}
- } else if (!arg.static_type.compatible (param.type_reference)) {
+ } else if (!arg.static_type.compatible (param.type_reference)
+ && !(arg is NullLiteral && param.direction == ParameterDirection.OUT)) {
expr.error = true;
Report.error (arg.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;
@@ -1844,27 +1845,27 @@
}
if (arg_type == 0) {
- if (param.type_reference.is_ref) {
+ if (param.direction == ParameterDirection.REF) {
expr.error = true;
Report.error (arg.source_reference, "Argument %d: Cannot pass null to reference parameter".printf (i + 1));
return false;
- } else if (!param.type_reference.is_out && !param.type_reference.nullable) {
+ } else if (param.direction != ParameterDirection.OUT && !param.type_reference.nullable) {
Report.warning (arg.source_reference, "Argument %d: Cannot pass null to non-null parameter type".printf (i + 1));
}
} else if (arg_type == 1) {
- if (param.type_reference.is_ref || param.type_reference.is_out) {
+ if (param.direction != ParameterDirection.IN) {
expr.error = true;
Report.error (arg.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) {
+ if (param.direction != ParameterDirection.REF) {
expr.error = true;
Report.error (arg.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) {
+ if (param.direction != ParameterDirection.OUT) {
expr.error = true;
Report.error (arg.source_reference, "Argument %d: Cannot pass out argument to non-output parameter".printf (i + 1));
return false;
Modified: trunk/vala/valasymbolresolver.vala
==============================================================================
--- trunk/vala/valasymbolresolver.vala (original)
+++ trunk/vala/valasymbolresolver.vala Tue Apr 15 21:07:19 2008
@@ -267,8 +267,6 @@
type.source_reference = unresolved_type.source_reference;
type.takes_ownership = unresolved_type.takes_ownership;
type.transfers_ownership = unresolved_type.transfers_ownership;
- type.is_ref = unresolved_type.is_ref;
- type.is_out = unresolved_type.is_out;
type.nullable = unresolved_type.nullable;
foreach (DataType type_arg in unresolved_type.get_type_arguments ()) {
type.add_type_argument (type_arg);
@@ -278,8 +276,6 @@
var base_type = type;
base_type.takes_ownership = false;
base_type.transfers_ownership = false;
- base_type.is_ref = false;
- base_type.is_out = false;
base_type.nullable = false;
type = new PointerType (base_type);
@@ -298,8 +294,6 @@
if (unresolved_type.array_rank > 0) {
var element_type = type;
element_type.transfers_ownership = false;
- element_type.is_ref = false;
- element_type.is_out = false;
element_type.nullable = false;
type = new ArrayType (element_type, unresolved_type.array_rank, unresolved_type.source_reference);
@@ -307,8 +301,6 @@
type.takes_ownership = unresolved_type.takes_ownership;
type.transfers_ownership = unresolved_type.transfers_ownership;
- type.is_ref = unresolved_type.is_ref;
- type.is_out = unresolved_type.is_out;
type.nullable = unresolved_type.nullable;
}
Modified: trunk/vala/valatypeparametertype.vala
==============================================================================
--- trunk/vala/valatypeparametertype.vala (original)
+++ trunk/vala/valatypeparametertype.vala Tue Apr 15 21:07:19 2008
@@ -35,10 +35,8 @@
result.source_reference = source_reference;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.floating_reference = floating_reference;
- result.is_ref = is_ref;
return result;
}
Modified: trunk/vala/valaunresolvedtype.vala
==============================================================================
--- trunk/vala/valaunresolvedtype.vala (original)
+++ trunk/vala/valaunresolvedtype.vala Tue Apr 15 21:07:19 2008
@@ -107,12 +107,10 @@
result.source_reference = source_reference;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.unresolved_symbol = unresolved_symbol.copy ();
result.array_rank = array_rank;
result.pointer_level = pointer_level;
- result.is_ref = is_ref;
result.is_weak = is_weak;
foreach (DataType arg in get_type_arguments ()) {
Modified: trunk/vala/valavaluetype.vala
==============================================================================
--- trunk/vala/valavaluetype.vala (original)
+++ trunk/vala/valavaluetype.vala Tue Apr 15 21:07:19 2008
@@ -41,10 +41,8 @@
result.source_reference = source_reference;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
- result.is_out = is_out;
result.nullable = nullable;
result.floating_reference = floating_reference;
- result.is_ref = is_ref;
foreach (DataType arg in get_type_arguments ()) {
result.add_type_argument (arg.copy ());
@@ -55,11 +53,8 @@
public override string? get_cname (bool var_type, bool const_type) {
string ptr = "";
- if (is_ref || is_out) {
- ptr += "*";
- }
if (nullable) {
- ptr += "*";
+ ptr = "*";
}
return type_symbol.get_cname (const_type) + ptr;
}
Modified: trunk/vapigen/valagidlparser.vala
==============================================================================
--- trunk/vapigen/valagidlparser.vala (original)
+++ trunk/vapigen/valagidlparser.vala Tue Apr 15 21:07:19 2008
@@ -282,7 +282,7 @@
private Delegate? parse_delegate (IdlNodeFunction f_node) {
weak IdlNode node = (IdlNode) f_node;
-
+
var cb = new Delegate (node.name, parse_param (f_node.result), current_source_reference);
cb.access = SymbolAccessibility.PUBLIC;
@@ -314,7 +314,9 @@
param_name = "str";
}
- var p = new FormalParameter (param_name, parse_param (param));
+ ParameterDirection direction;
+ var p = new FormalParameter (param_name, parse_param (param, out direction));
+ p.direction = direction;
cb.add_parameter (p);
}
@@ -978,7 +980,9 @@
current_data_type = null;
}
- private UnresolvedType? parse_type (IdlNodeType type_node) {
+ private UnresolvedType? parse_type (IdlNodeType type_node, out ParameterDirection direction = null) {
+ ParameterDirection dir = ParameterDirection.IN;
+
var type = new UnresolvedType ();
if (type_node.tag == TypeTag.VOID) {
if (type_node.is_pointer) {
@@ -1050,7 +1054,7 @@
(n == "gchar" || n == "char")) {
type.unresolved_symbol = new UnresolvedSymbol (null, "string");
if (type_node.unparsed.has_suffix ("**")) {
- type.is_out = true;
+ dir = ParameterDirection.OUT;
}
} else if (n == "gunichar") {
type.unresolved_symbol = new UnresolvedSymbol (null, "unichar");
@@ -1099,15 +1103,18 @@
parse_type_string (type, n);
if (is_simple_type (n)) {
if (type_node.is_pointer) {
- type.is_out = true;
+ dir = ParameterDirection.OUT;
}
} else if (type_node.unparsed.has_suffix ("**")) {
- type.is_out = true;
+ dir = ParameterDirection.OUT;
}
}
} else {
stdout.printf ("%d\n", type_node.tag);
}
+ if (&direction != null) {
+ direction = dir;
+ }
return type;
}
@@ -1175,8 +1182,8 @@
}
}
- private UnresolvedType parse_param (IdlNodeParam param) {
- var type = parse_type (param.type);
+ private UnresolvedType parse_param (IdlNodeParam param, out ParameterDirection direction = null) {
+ var type = parse_type (param.type, out direction);
// disable for now as null_ok not yet correctly set
// type.non_null = !param.null_ok;
@@ -1250,7 +1257,6 @@
} else if (nv[0] == "is_array") {
if (eval (nv[1]) == "1") {
return_type.array_rank = 1;
- return_type.is_out = false;
}
} else if (nv[0] == "throws") {
if (eval (nv[1]) == "0") {
@@ -1309,8 +1315,10 @@
// avoid conflict with string type
param_name = "str";
}
- var param_type = parse_param (param);
+ ParameterDirection direction;
+ var param_type = parse_param (param, out direction);
var p = new FormalParameter (param_name, param_type);
+ p.direction = direction;
bool hide_param = false;
bool show_param = false;
@@ -1323,15 +1331,15 @@
if (nv[0] == "is_array") {
if (eval (nv[1]) == "1") {
param_type.array_rank = 1;
- param_type.is_out = false;
+ p.direction = ParameterDirection.IN;
}
} else if (nv[0] == "is_out") {
if (eval (nv[1]) == "1") {
- param_type.is_out = true;
+ p.direction = ParameterDirection.OUT;
}
} else if (nv[0] == "is_ref") {
if (eval (nv[1]) == "1") {
- param_type.is_ref = true;
+ p.direction = ParameterDirection.REF;
}
} else if (nv[0] == "nullable") {
if (eval (nv[1]) == "1") {
@@ -1370,7 +1378,7 @@
if (last_param != null && p.name == "n_" + last_param.name) {
// last_param is array, p is array length
last_param_type.array_rank = 1;
- last_param_type.is_out = false;
+ last_param.direction = ParameterDirection.IN;
// hide array length param
hide_param = true;
@@ -1657,8 +1665,10 @@
weak IdlNode param_node = (IdlNode) param;
- var param_type = parse_param (param);
+ ParameterDirection direction;
+ var param_type = parse_param (param, out direction);
var p = new FormalParameter (param_node.name, param_type);
+ p.direction = direction;
sig.add_parameter (p);
var attributes = get_attributes ("%s::%s.%s".printf (current_data_type.get_cname (), sig.name, param_node.name));
@@ -1669,15 +1679,15 @@
if (nv[0] == "is_array") {
if (eval (nv[1]) == "1") {
param_type.array_rank = 1;
- param_type.is_out = false;
+ p.direction = ParameterDirection.IN;
}
} else if (nv[0] == "is_out") {
if (eval (nv[1]) == "1") {
- param_type.is_out = true;
+ p.direction = ParameterDirection.OUT;
}
} else if (nv[0] == "is_ref") {
if (eval (nv[1]) == "1") {
- param_type.is_ref = true;
+ p.direction = ParameterDirection.REF;
}
} else if (nv[0] == "nullable") {
if (eval (nv[1]) == "1") {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]