[vala/wip/attributes: 115/121] On demand ccode arguments check
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 115/121] On demand ccode arguments check
- Date: Mon, 4 Jul 2011 17:18:25 +0000 (UTC)
commit 64f5aa7b3435a085bf9704dbe7e3c04298a374e1
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jul 3 21:00:54 2011 +0200
On demand ccode arguments check
codegen/valaccodebasemodule.vala | 378 ++++++++++++++++++++++--------------
codegen/valaccodemethodmodule.vala | 4 +
codegen/valadovabasemodule.vala | 2 +-
codegen/valagirwriter.vala | 4 +-
4 files changed, 242 insertions(+), 146 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c80d242..fe443f9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -544,7 +544,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
// add appropriate include file
- foreach (string header_filename in get_ccode_header_filenames (sym)) {
+ foreach (string header_filename in get_ccode_header_filenames (sym).split (",")) {
decl_space.add_include (header_filename, !sym.external_package);
}
// declaration complete
@@ -5595,7 +5595,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public static List<string> get_ccode_header_filenames (Symbol sym) {
+ public static string get_ccode_header_filenames (Symbol sym) {
return get_ccode_attribute(sym).header_filenames;
}
@@ -6208,13 +6208,19 @@ public class Vala.GLibValue : TargetValue {
}
public class Vala.CCodeAttribute : AttributeCache {
- public weak CodeNode node;
- public weak Symbol sym;
+ private weak CodeNode node;
+ private weak Symbol sym;
+ private Attribute ccode;
public string name {
get {
if (_name == null) {
- _name = get_default_name ();
+ if (ccode != null) {
+ _name = ccode.get_string ("cname");
+ }
+ if (_name == null) {
+ _name = get_default_name ();
+ }
}
return _name;
}
@@ -6223,28 +6229,11 @@ public class Vala.CCodeAttribute : AttributeCache {
public string const_name {
get {
if (_const_name == null) {
- if (node is DataType) {
- var type = (DataType) node;
- string ptr;
- TypeSymbol t;
- // FIXME: workaround to make constant arrays possible
- if (type is ArrayType) {
- t = ((ArrayType) type).element_type.data_type;
- } else {
- t = type.data_type;
- }
- if (!t.is_reference_type ()) {
- ptr = "";
- } else {
- ptr = "*";
- }
-
- _const_name = "const %s%s".printf (CCodeBaseModule.get_ccode_name (t), ptr);
- } else {
- _const_name = CCodeBaseModule.get_ccode_name (node);
- if (node is Class && ((Class) node).is_immutable) {
- _const_name = "const %s".printf (_const_name);
- }
+ if (ccode != null) {
+ _const_name = ccode.get_string ("const_cname");
+ }
+ if (_const_name == null) {
+ _const_name = get_default_const_name ();
}
}
return _const_name;
@@ -6254,16 +6243,26 @@ public class Vala.CCodeAttribute : AttributeCache {
public string type_name {
get {
if (_type_name == null) {
- _type_name = "%sIface".printf (CCodeBaseModule.get_ccode_name (sym));
+ if (ccode != null) {
+ _type_name = ccode.get_string ("type_cname");
+ }
+ if (_type_name == null) {
+ _type_name = "%sIface".printf (CCodeBaseModule.get_ccode_name (sym));
+ }
}
return _type_name;
}
}
- public List<string> header_filenames {
+ public string header_filenames {
get {
if (_header_filenames == null) {
- _header_filenames = get_default_header_filenames ();
+ if (ccode != null) {
+ _header_filenames = ccode.get_string ("cheader_filename");
+ }
+ if (_header_filenames == null) {
+ _header_filenames = get_default_header_filenames ();
+ }
}
return _header_filenames;
}
@@ -6272,7 +6271,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string prefix {
get {
if (_prefix == null) {
- _prefix = get_default_prefix ();
+ if (ccode != null) {
+ _prefix = ccode.get_string ("cprefix");
+ }
+ if (_prefix == null) {
+ _prefix = get_default_prefix ();
+ }
}
return _prefix;
}
@@ -6281,7 +6285,15 @@ public class Vala.CCodeAttribute : AttributeCache {
public string lower_case_prefix {
get {
if (_lower_case_prefix == null) {
- _lower_case_prefix = get_default_lower_case_prefix ();
+ if (ccode != null) {
+ _lower_case_prefix = ccode.get_string ("lower_case_cprefix");
+ if (_lower_case_prefix == null && (sym is ObjectTypeSymbol || sym is Struct)) {
+ _lower_case_prefix = ccode.get_string ("cprefix");
+ }
+ }
+ if (_lower_case_prefix == null) {
+ _lower_case_prefix = get_default_lower_case_prefix ();
+ }
}
return _lower_case_prefix;
}
@@ -6290,7 +6302,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string lower_case_suffix {
get {
if (_lower_case_suffix == null) {
- _lower_case_suffix = get_default_lower_case_suffix ();
+ if (ccode != null) {
+ _lower_case_suffix = ccode.get_string ("lower_case_csuffix");
+ }
+ if (_lower_case_suffix == null) {
+ _lower_case_suffix = get_default_lower_case_suffix ();
+ }
}
return _lower_case_suffix;
}
@@ -6299,7 +6316,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string ref_function {
get {
if (_ref_function == null) {
- _ref_function = get_default_ref_function ();
+ if (ccode != null) {
+ _ref_function = ccode.get_string ("ref_function");
+ }
+ if (_ref_function == null) {
+ _ref_function = get_default_ref_function ();
+ }
}
return _ref_function;
}
@@ -6308,11 +6330,15 @@ public class Vala.CCodeAttribute : AttributeCache {
public bool ref_function_void {
get {
if (_ref_function_void == null) {
- var cl = (Class) sym;
- if (cl.base_class != null) {
- _ref_function_void = CCodeBaseModule.get_ccode_ref_function_void (cl.base_class);
+ if (ccode != null && ccode.has_argument ("ref_function_void")) {
+ _ref_function_void = ccode.get_bool ("ref_function_void");
} else {
- _ref_function_void = false;
+ var cl = (Class) sym;
+ if (cl.base_class != null) {
+ _ref_function_void = CCodeBaseModule.get_ccode_ref_function_void (cl.base_class);
+ } else {
+ _ref_function_void = false;
+ }
}
}
return _ref_function_void;
@@ -6322,7 +6348,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string unref_function {
get {
if (_unref_function == null) {
- _unref_function = get_default_unref_function ();
+ if (ccode != null) {
+ _unref_function = ccode.get_string ("unref_function");
+ }
+ if (_unref_function == null) {
+ _unref_function = get_default_unref_function ();
+ }
}
return _unref_function;
}
@@ -6331,7 +6362,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string ref_sink_function {
get {
if (_ref_sink_function == null) {
- _ref_sink_function = get_default_ref_sink_function ();
+ if (ccode != null) {
+ _ref_sink_function = ccode.get_string ("ref_sink_function");
+ }
+ if (_ref_sink_function == null) {
+ _ref_sink_function = get_default_ref_sink_function ();
+ }
}
return _ref_sink_function;
}
@@ -6340,10 +6376,15 @@ public class Vala.CCodeAttribute : AttributeCache {
public string copy_function {
get {
if (_copy_function == null) {
- if (sym is Struct) {
- _copy_function = lower_case_prefix + "copy";
- } else {
- _copy_function = "";
+ if (ccode != null) {
+ _copy_function = ccode.get_string ("copy_function");
+ }
+ if (_copy_function == null) {
+ if (sym is Struct) {
+ _copy_function = lower_case_prefix + "copy";
+ } else {
+ _copy_function = "";
+ }
}
}
return _copy_function;
@@ -6353,10 +6394,15 @@ public class Vala.CCodeAttribute : AttributeCache {
public string destroy_function {
get {
if (_destroy_function == null) {
- if (sym is Struct) {
- _destroy_function = lower_case_prefix + "destroy";
- } else {
- _destroy_function = "";
+ if (ccode != null) {
+ _destroy_function = ccode.get_string ("destroy_function");
+ }
+ if (_destroy_function == null) {
+ if (sym is Struct) {
+ _destroy_function = lower_case_prefix + "destroy";
+ } else {
+ _destroy_function = "";
+ }
}
}
return _destroy_function;
@@ -6366,7 +6412,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string free_function {
get {
if (_free_function == null) {
- _free_function = get_default_free_function ();
+ if (ccode != null) {
+ _free_function = ccode.get_string ("free_function");
+ }
+ if (_free_function == null) {
+ _free_function = get_default_free_function ();
+ }
}
return _free_function;
}
@@ -6375,7 +6426,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string type_id {
get {
if (_type_id == null) {
- _type_id = get_default_type_id ();
+ if (ccode != null) {
+ _type_id = ccode.get_string ("type_id");
+ }
+ if (_type_id == null) {
+ _type_id = get_default_type_id ();
+ }
}
return _type_id;
}
@@ -6384,7 +6440,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string marshaller_type_name {
get {
if (_marshaller_type_name == null) {
- _marshaller_type_name = get_default_marshaller_type_name ();
+ if (ccode != null) {
+ _marshaller_type_name = ccode.get_string ("marshaller_type_name");
+ }
+ if (_marshaller_type_name == null) {
+ _marshaller_type_name = get_default_marshaller_type_name ();
+ }
}
return _marshaller_type_name;
}
@@ -6393,7 +6454,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string get_value_function {
get {
if (_get_value_function == null) {
- _get_value_function = get_default_get_value_function ();
+ if (ccode != null) {
+ _get_value_function = ccode.get_string ("get_value_function");
+ }
+ if (_get_value_function == null) {
+ _get_value_function = get_default_get_value_function ();
+ }
}
return _get_value_function;
}
@@ -6402,7 +6468,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string set_value_function {
get {
if (_set_value_function == null) {
- _set_value_function = get_default_set_value_function ();
+ if (ccode != null) {
+ _set_value_function = ccode.get_string ("set_value_function");
+ }
+ if (_set_value_function == null) {
+ _set_value_function = get_default_set_value_function ();
+ }
}
return _set_value_function;
}
@@ -6411,7 +6482,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string take_value_function {
get {
if (_take_value_function == null) {
- _take_value_function = get_default_take_value_function ();
+ if (ccode != null) {
+ _take_value_function = ccode.get_string ("take_value_function");
+ }
+ if (_take_value_function == null) {
+ _take_value_function = get_default_take_value_function ();
+ }
}
return _take_value_function;
}
@@ -6420,7 +6496,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string param_spec_function {
get {
if (_param_spec_function == null) {
- _param_spec_function = get_default_param_spec_function ();
+ if (ccode != null) {
+ _param_spec_function = ccode.get_string ("param_spec_function");
+ }
+ if (_param_spec_function == null) {
+ _param_spec_function = get_default_param_spec_function ();
+ }
}
return _param_spec_function;
}
@@ -6429,7 +6510,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string default_value {
get {
if (_default_value == null) {
- _default_value = get_default_default_value ();
+ if (ccode != null) {
+ _default_value = ccode.get_string ("default_value");
+ }
+ if (_default_value == null) {
+ _default_value = get_default_default_value ();
+ }
}
return _default_value;
}
@@ -6438,16 +6524,20 @@ public class Vala.CCodeAttribute : AttributeCache {
public double pos {
get {
if (_pos == null) {
- var param = (Parameter) node;
- var sym = param.parent_symbol;
- if (sym is Method) {
- _pos = ((Method) sym).get_parameters().index_of (param) + 1.0;
- } else if (sym is Delegate) {
- _pos = ((Delegate) sym).get_parameters().index_of (param) + 1.0;
- } else if (sym is Signal) {
- _pos = ((Signal) sym).get_parameters().index_of (param) + 1.0;
+ if (ccode != null && ccode.has_argument ("pos")) {
+ _pos = ccode.get_double ("pos");
} else {
- _pos = 0.0;
+ var param = (Parameter) node;
+ var sym = param.parent_symbol;
+ if (sym is Method) {
+ _pos = ((Method) sym).get_parameters().index_of (param) + 1.0;
+ } else if (sym is Delegate) {
+ _pos = ((Delegate) sym).get_parameters().index_of (param) + 1.0;
+ } else if (sym is Signal) {
+ _pos = ((Signal) sym).get_parameters().index_of (param) + 1.0;
+ } else {
+ _pos = 0.0;
+ }
}
}
return _pos;
@@ -6457,7 +6547,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string real_name {
get {
if (_real_name == null) {
- _real_name = get_default_real_name ();
+ if (ccode != null && sym is CreationMethod) {
+ _real_name = ccode.get_string ("construct_function");
+ }
+ if (_real_name == null) {
+ _real_name = get_default_real_name ();
+ }
}
return _real_name;
}
@@ -6466,7 +6561,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string vfunc_name {
get {
if (_vfunc_name == null) {
- _vfunc_name = sym.name;
+ if (ccode != null) {
+ _vfunc_name = ccode.get_string ("vfunc_name");
+ }
+ if (_vfunc_name == null) {
+ _vfunc_name = sym.name;
+ }
}
return _vfunc_name;
}
@@ -6475,7 +6575,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string finish_name {
get {
if (_finish_name == null) {
- _finish_name = get_finish_name_for_basename (name);
+ if (ccode != null) {
+ _finish_name = ccode.get_string ("finish_name");
+ }
+ if (_finish_name == null) {
+ _finish_name = get_finish_name_for_basename (name);
+ }
}
return _finish_name;
}
@@ -6510,7 +6615,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _name;
private string _const_name;
private string _type_name;
- private List<string> _header_filenames;
+ private string _header_filenames;
private string _prefix;
private string _lower_case_prefix;
private string _lower_case_suffix;
@@ -6541,75 +6646,24 @@ public class Vala.CCodeAttribute : AttributeCache {
this.node = node;
this.sym = node as Symbol;
- var attr = node.get_attribute ("CCode");
- if (attr != null) {
- _name = attr.get_string ("cname");
- _const_name = attr.get_string ("const_cname");
- _type_name = attr.get_string ("type_cname");
- var headers = attr.get_string ("cheader_filename");
- if (headers != null) {
- _header_filenames = new ArrayList<string> ();
- foreach (var header in headers.split (",")) {
- _header_filenames.add (header);
- }
- }
- _prefix = attr.get_string ("cprefix");
- _lower_case_prefix = attr.get_string ("lower_case_cprefix");
- if (_lower_case_prefix == null && (sym is ObjectTypeSymbol || sym is Struct)) {
- _lower_case_prefix = _prefix;
- }
- _lower_case_suffix = attr.get_string ("lower_case_csuffix");
- _ref_function = attr.get_string ("ref_function");
- if (attr.has_argument ("ref_function_void")) {
- _ref_function_void = attr.get_bool ("ref_function_void");
- }
- _unref_function = attr.get_string ("unref_function");
- _ref_sink_function = attr.get_string ("ref_sink_function");
- _copy_function = attr.get_string ("copy_function");
- _destroy_function = attr.get_string ("destroy_function");
- _free_function = attr.get_string ("free_function");
- _type_id = attr.get_string ("type_id");
- _marshaller_type_name = attr.get_string ("marshaller_type_name");
- _get_value_function = attr.get_string ("get_value_function");
- _set_value_function = attr.get_string ("set_value_function");
- _take_value_function = attr.get_string ("take_value_function");
- _param_spec_function = attr.get_string ("param_spec_function");
- _default_value = attr.get_string ("default_value");
- if (attr.has_argument ("array_length")) {
- no_array_length = !attr.get_bool ("array_length");
- }
- array_length_type = attr.get_string ("array_length_type");
- array_null_terminated = attr.get_bool ("array_null_terminated");
- if (attr.has_argument ("pos")) {
- _pos = attr.get_double ("pos");
- }
- _vfunc_name = attr.get_string ("vfunc_name");
- _finish_name = attr.get_string ("finish_name");
- if (sym is CreationMethod) {
- _real_name = attr.get_string ("construct_function");
- }
- if (attr.has_argument ("delegate_target")) {
- no_delegate_target = !attr.get_bool ("delegate_target");
- }
- sentinel = attr.get_string ("sentinel");
+ ccode = node.get_attribute ("CCode");
+ if (ccode != null) {
+ if (ccode.has_argument ("array_length")) {
+ no_array_length = !ccode.get_bool ("array_length");
+ }
+ array_length_type = ccode.get_string ("array_length_type");
+ array_null_terminated = ccode.get_bool ("array_null_terminated");
+ if (ccode.has_argument ("pos")) {
+ _pos = ccode.get_double ("pos");
+ }
+ if (ccode.has_argument ("delegate_target")) {
+ no_delegate_target = !ccode.get_bool ("delegate_target");
+ }
+ sentinel = ccode.get_string ("sentinel");
}
if (node.get_attribute ("NoArrayLength") != null) {
- Report.deprecated (node.source_reference, "NoArrayLength attribute is deprecated, use [CCode (array_length = false)] instead.");
no_array_length = true;
}
- if (_name == null && sym != null && !sym.external && sym is Struct) {
- var st = (Struct) sym;
- if (st.is_boolean_type ()) {
- // typedef for boolean types
- _name = "bool";
- } else if (st.is_integer_type ()) {
- // typedef for integral types
- _name = "%sint%d_t".printf (st.signed ? "" : "u", st.width);
- } else if (st.is_floating_type ()) {
- // typedef for floating types
- _name = st.width == 64 ? "double" : "float";
- }
- }
if (sentinel == null) {
sentinel = "NULL";
}
@@ -6665,6 +6719,20 @@ public class Vala.CCodeAttribute : AttributeCache {
}
} else if (sym is Signal) {
return Symbol.camel_case_to_lower_case (sym.name);
+ } else if (sym is Struct && !sym.external) {
+ var st = (Struct) sym;
+ if (st.is_boolean_type ()) {
+ // typedef for boolean types
+ return "bool";
+ } else if (st.is_integer_type ()) {
+ // typedef for integral types
+ return "%sint%d_t".printf (st.signed ? "" : "u", st.width);
+ } else if (st.is_floating_type ()) {
+ // typedef for floating types
+ return st.width == 64 ? "double" : "float";
+ } else {
+ return "%s%s".printf (CCodeBaseModule.get_ccode_prefix (sym.parent_symbol), sym.name);
+ }
} else {
return "%s%s".printf (CCodeBaseModule.get_ccode_prefix (sym.parent_symbol), sym.name);
}
@@ -6750,19 +6818,16 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
- private List<string> get_default_header_filenames () {
+ private string get_default_header_filenames () {
if (sym is DynamicProperty || sym is DynamicMethod) {
- return new ArrayList<string> ();
+ return "";
} else if (sym.parent_symbol != null) {
return CCodeBaseModule.get_ccode_header_filenames (sym.parent_symbol);
- } else {
- var headers = new ArrayList<string> ();
- if (sym.source_reference != null && !sym.external_package) {
- // don't add default include directives for VAPI files
- headers.add (sym.source_reference.file.get_cinclude_filename ());
- }
- return headers;
+ } else if (sym.source_reference != null && !sym.external_package) {
+ // don't add default include directives for VAPI files
+ return sym.source_reference.file.get_cinclude_filename ();
}
+ return "";
}
private string get_default_prefix () {
@@ -7259,4 +7324,31 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
}
+
+ private string get_default_const_name () {
+ if (node is DataType) {
+ var type = (DataType) node;
+ string ptr;
+ TypeSymbol t;
+ // FIXME: workaround to make constant arrays possible
+ if (type is ArrayType) {
+ t = ((ArrayType) type).element_type.data_type;
+ } else {
+ t = type.data_type;
+ }
+ if (!t.is_reference_type ()) {
+ ptr = "";
+ } else {
+ ptr = "*";
+ }
+
+ return "const %s%s".printf (CCodeBaseModule.get_ccode_name (t), ptr);
+ } else {
+ if (node is Class && ((Class) node).is_immutable) {
+ return "const %s".printf (name);
+ } else {
+ return name;
+ }
+ }
+ }
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 3f3d4e3..258b612 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -257,6 +257,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
check_type (m.return_type);
+ if (m.get_attribute ("NoArrayLength") != null) {
+ Report.deprecated (m.source_reference, "NoArrayLength attribute is deprecated, use [CCode (array_length = false)] instead.");
+ }
+
if (m is CreationMethod) {
var cl = current_type_symbol as Class;
if (cl != null && !cl.is_compact) {
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 3f056a7..49bcb3d 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -333,7 +333,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
}
if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
// add appropriate include file
- foreach (string header_filename in CCodeBaseModule.get_ccode_header_filenames (sym)) {
+ foreach (string header_filename in CCodeBaseModule.get_ccode_header_filenames (sym).split (",")) {
decl_space.add_include (header_filename, !sym.external_package);
}
// declaration complete
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index d40931c..b5f676e 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -128,11 +128,11 @@ public class Vala.GIRWriter : CodeVisitor {
private void write_c_includes (Namespace ns) {
// Collect C header filenames
Set<string> header_filenames = new HashSet<string> (str_hash, str_equal);
- foreach (string c_header_filename in CCodeBaseModule.get_ccode_header_filenames (ns)) {
+ foreach (string c_header_filename in CCodeBaseModule.get_ccode_header_filenames (ns).split (",")) {
header_filenames.add (c_header_filename);
}
foreach (Symbol symbol in ns.scope.get_symbol_table ().get_values ()) {
- foreach (string c_header_filename in CCodeBaseModule.get_ccode_header_filenames (symbol)) {
+ foreach (string c_header_filename in CCodeBaseModule.get_ccode_header_filenames (symbol).split (",")) {
header_filenames.add (c_header_filename);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]