[vala/wip/girparser: 14/17] girparser: Improve function to method conversion



commit c47ec4cf93b8e60f2b30d667cb44cca7415e04bb
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Dec 10 20:02:46 2016 +0100

    girparser: Improve function to method conversion
    
    Update the array-length, closure and destroy indexes if needed.
    Drop instance_pos attribute if it refers to the first parameter which is
    the default anyway.

 vala/valagirparser.vala |   39 +++++++++++++++++++++++++++++----------
 1 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 892afb4..a4150fd 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -3145,6 +3145,18 @@ public class Vala.GirParser : CodeVisitor {
                        s.set_attribute_string ("CCode", "finish_name", metadata.get_string 
(ArgumentType.FINISH_NAME));
                }
 
+               int instance_idx = -2;
+               if (element_name == "function" && symbol_type == "method") {
+                       if (metadata.has_argument (ArgumentType.INSTANCE_IDX)) {
+                               instance_idx = metadata.get_integer (ArgumentType.INSTANCE_IDX);
+                               if (instance_idx != 0) {
+                                       s.set_attribute_double ("CCode", "instance_pos", instance_idx + 0.5);
+                               }
+                       } else {
+                               Report.error (get_current_src (), "instance_idx required when converting 
function to method");
+                       }
+               }
+
                var parameters = new ArrayList<ParameterInfo> ();
                current.array_length_parameters = new ArrayList<int> ();
                current.closure_parameters = new ArrayList<int> ();
@@ -3153,13 +3165,21 @@ public class Vala.GirParser : CodeVisitor {
                        start_element ("parameters");
                        next ();
 
+                       var current_parameter_idx = -1;
                        while (current_token == MarkupTokenType.START_ELEMENT) {
+                               current_parameter_idx++;
+
                                if (reader.name == "instance-parameter" &&
                                    !(symbol_type == "function" || symbol_type == "constructor")) {
                                        skip_element ();
                                        continue;
                                }
 
+                               if (instance_idx > -2 && instance_idx == current_parameter_idx) {
+                                       skip_element ();
+                                       continue;
+                               }
+
                                if (!push_metadata ()) {
                                        skip_element ();
                                        continue;
@@ -3172,12 +3192,21 @@ public class Vala.GirParser : CodeVisitor {
                                default_param_name = "arg%d".printf (parameters.size);
                                var param = parse_parameter (out array_length_idx, out closure_idx, out 
destroy_idx, out scope, out param_comment, default_param_name);
                                if (array_length_idx != -1) {
+                                       if (instance_idx > -2 && instance_idx < array_length_idx) {
+                                               array_length_idx--;
+                                       }
                                        current.array_length_parameters.add (array_length_idx);
                                }
                                if (closure_idx != -1) {
+                                       if (instance_idx > -2 && instance_idx < closure_idx) {
+                                               closure_idx--;
+                                       }
                                        current.closure_parameters.add (closure_idx);
                                }
                                if (destroy_idx != -1) {
+                                       if (instance_idx > -2 && instance_idx < destroy_idx) {
+                                               destroy_idx--;
+                                       }
                                        current.destroy_parameters.add (destroy_idx);
                                }
                                if (param_comment != null) {
@@ -3219,16 +3248,6 @@ public class Vala.GirParser : CodeVisitor {
                        }
                }
 
-               if (element_name == "function" && symbol_type == "method") {
-                       if (metadata.has_argument (ArgumentType.INSTANCE_IDX)) {
-                               int instance_pos = metadata.get_integer (ArgumentType.INSTANCE_IDX);
-                               s.set_attribute_double ("CCode", "instance_pos", instance_pos + 0.5);
-                               parameters.remove_at (instance_pos);
-                       } else {
-                               Report.error (get_current_src (), "instance_idx required when converting 
function to method");
-                       }
-               }
-
                pop_node ();
                end_element (element_name);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]