[vala/staging: 3/5] Make use of Callable to replace some if-else-trees
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 3/5] Make use of Callable to replace some if-else-trees
- Date: Tue, 11 Oct 2016 13:48:00 +0000 (UTC)
commit 83b0feb5fe500b362cb835e9d530d5d082277e5b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Oct 10 20:22:10 2016 +0200
Make use of Callable to replace some if-else-trees
codegen/valaccodeattribute.vala | 8 ++------
vala/valagirparser.vala | 31 +++++++------------------------
2 files changed, 9 insertions(+), 30 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 0383fe3..f9c9ab6 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -376,12 +376,8 @@ public class Vala.CCodeAttribute : AttributeCache {
} else {
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 (sym is Callable) {
+ _pos = ((Callable) sym).get_parameters ().index_of (param) +
1.0;
} else {
_pos = 0.0;
}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 742868c..2a0e18d 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1515,12 +1515,7 @@ public class Vala.GirParser : CodeVisitor {
}
void assume_parameter_names (Signal sig, Symbol sym, bool skip_first) {
- Iterator<Parameter> iter;
- if (sym is Method) {
- iter = ((Method) sym).get_parameters ().iterator ();
- } else {
- iter = ((Delegate) sym).get_parameters ().iterator ();
- }
+ var iter = ((Callable) sym).get_parameters ().iterator ();
bool first = true;
foreach (var param in sig.get_parameters ()) {
if (!iter.next ()) {
@@ -3574,12 +3569,8 @@ public class Vala.GirParser : CodeVisitor {
List<ParameterInfo> parameters = node.parameters;
DataType return_type = null;
- if (s is Method) {
- return_type = ((Method) s).return_type;
- } else if (s is Delegate) {
- return_type = ((Delegate) s).return_type;
- } else if (s is Signal) {
- return_type = ((Signal) s).return_type;
+ if (s is Callable) {
+ return_type = ((Callable) s).return_type;
}
if (return_type is ArrayType && node.return_array_length_idx >= 0) {
@@ -3691,12 +3682,8 @@ public class Vala.GirParser : CodeVisitor {
/* add_parameter sets carray_length_parameter_position and
cdelegate_target_parameter_position
so do it first*/
- if (s is Method) {
- ((Method) s).add_parameter (info.param);
- } else if (s is Delegate) {
- ((Delegate) s).add_parameter (info.param);
- } else if (s is Signal) {
- ((Signal) s).add_parameter (info.param);
+ if (s is Callable) {
+ ((Callable) s).add_parameter (info.param);
}
if (info.array_length_idx != -1) {
@@ -3754,12 +3741,8 @@ public class Vala.GirParser : CodeVisitor {
set_array_ccode (s, parameters[node.return_array_length_idx]);
}
- if (s is Method) {
- ((Method) s).return_type = return_type;
- } else if (s is Delegate) {
- ((Delegate) s).return_type = return_type;
- } else if (s is Signal) {
- ((Signal) s).return_type = return_type;
+ if (s is Callable) {
+ ((Callable) s).return_type = return_type;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]