[vala] codegen: Inherit array_{length, null_terminated} from base parameter
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Inherit array_{length, null_terminated} from base parameter
- Date: Sun, 29 Sep 2013 18:02:17 +0000 (UTC)
commit f3aeabaf16a5e9a9ad0aa5d64b18652c203c602e
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Sep 29 17:35:47 2013 +0200
codegen: Inherit array_{length,null_terminated} from base parameter
First commit to start inheriting ccode attributes of parameters
from base parameters of base methods.
Partially fixes bug 642885.
codegen/valaccodeattribute.vala | 60 +++++++++++++++++++++++++++++++++------
tests/Makefile.am | 1 +
tests/methods/bug642885.vala | 36 +++++++++++++++++++++++
vala/valaparameter.vala | 16 ++++++++++
4 files changed, 104 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 82a74f7..05745df 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -468,9 +468,36 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
- public bool array_length { get; private set; }
+ public bool array_length {
+ get {
+ if (_array_length == null) {
+ if (node.get_attribute ("NoArrayLength") != null) {
+ // deprecated
+ _array_length = false;
+ } else if (ccode != null && ccode.has_argument ("array_length")) {
+ _array_length = ccode.get_bool ("array_length");
+ } else {
+ _array_length = get_default_array_length ();
+ }
+ }
+ return _array_length;
+ }
+ }
+
+ public bool array_null_terminated {
+ get {
+ if (_array_null_terminated == null) {
+ if (ccode != null && ccode.has_argument ("array_null_terminated")) {
+ _array_null_terminated = ccode.get_bool ("array_null_terminated");
+ } else {
+ _array_null_terminated = get_default_array_null_terminated ();
+ }
+ }
+ return _array_null_terminated;
+ }
+ }
+
public string? array_length_type { get; private set; }
- public bool array_null_terminated { get; private set; }
public string? array_length_name { get; private set; }
public string? array_length_expr { get; private set; }
public bool delegate_target { get; private set; }
@@ -512,6 +539,8 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _delegate_target_name;
private string _ctype;
private bool ctype_set = false;
+ private bool? _array_length;
+ private bool? _array_null_terminated;
private static int dynamic_method_id;
@@ -519,13 +548,10 @@ public class Vala.CCodeAttribute : AttributeCache {
this.node = node;
this.sym = node as Symbol;
- array_length = true;
delegate_target = true;
ccode = node.get_attribute ("CCode");
if (ccode != null) {
- array_length = ccode.get_bool ("array_length", true);
array_length_type = ccode.get_string ("array_length_type");
- array_null_terminated = ccode.get_bool ("array_null_terminated");
array_length_name = ccode.get_string ("array_length_cname");
array_length_expr = ccode.get_string ("array_length_cexpr");
if (ccode.has_argument ("pos")) {
@@ -534,10 +560,6 @@ public class Vala.CCodeAttribute : AttributeCache {
delegate_target = ccode.get_bool ("delegate_target", true);
sentinel = ccode.get_string ("sentinel");
}
- if (node.get_attribute ("NoArrayLength") != null) {
- // deprecated
- array_length = false;
- }
if (sentinel == null) {
sentinel = "NULL";
}
@@ -1274,4 +1296,24 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
}
+
+ private bool get_default_array_length () {
+ if (node is Parameter) {
+ var param = (Parameter) node;
+ if (param.base_parameter != null) {
+ return CCodeBaseModule.get_ccode_array_length (param.base_parameter);
+ }
+ }
+ return true;
+ }
+
+ private bool get_default_array_null_terminated () {
+ if (node is Parameter) {
+ var param = (Parameter) node;
+ if (param.base_parameter != null) {
+ return CCodeBaseModule.get_ccode_array_null_terminated (param.base_parameter);
+ }
+ }
+ return false;
+ }
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b84d433..de7e823 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ TESTS = \
methods/bug620673.vala \
methods/bug622570.vala \
methods/bug639054.vala \
+ methods/bug642885.vala \
methods/bug642899.vala \
methods/bug646345.vala \
methods/bug648320.vala \
diff --git a/tests/methods/bug642885.vala b/tests/methods/bug642885.vala
new file mode 100644
index 0000000..4acf97d
--- /dev/null
+++ b/tests/methods/bug642885.vala
@@ -0,0 +1,36 @@
+public class Foo : Application {
+ public bool activated = false;
+
+ public Foo () {
+ Object (application_id: "org.foo.bar");
+ }
+
+ protected override void activate () {
+ activated = true;
+ }
+
+ protected override bool local_command_line (ref unowned string[] arguments, out int exit_status) {
+ var option_context = new OptionContext ();
+
+ // FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=642885
+ unowned string[] args = arguments;
+
+ try {
+ option_context.parse (ref args);
+ } catch (OptionError e) {
+ exit_status = 1;
+ return true;
+ }
+
+ return base.local_command_line (ref arguments, out exit_status);
+ }
+}
+
+void main () {
+ string[] args = {""};
+ var app = new Foo ();
+ app.run (args);
+ assert (app.activated);
+}
+
+
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index c42d6f3..e65703d 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -45,6 +45,11 @@ public class Vala.Parameter : Variable {
public bool captured { get; set; }
/**
+ * The base parameter of this parameter relative to the base method.
+ */
+ public Parameter base_parameter { get; set; }
+
+ /**
* Creates a new formal parameter.
*
* @param name parameter name
@@ -180,6 +185,17 @@ public class Vala.Parameter : Variable {
}
}
+ var m = parent_symbol as Method;
+ if (m != null) {
+ Method base_method = m.base_method != null ? m.base_method : m.base_interface_method;
+ if (base_method != null && base_method != m) {
+ int index = m.get_parameters ().index_of (this);
+ if (index >= 0) {
+ base_parameter = base_method.get_parameters ().get (index);
+ }
+ }
+ }
+
context.analyzer.current_source_file = old_source_file;
context.analyzer.current_symbol = old_symbol;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]