Re: [Vala] Compile failed on .gir file



On 14-04-10 20:10, Jan Hudec wrote:
On Wed, Apr 14, 2010 at 18:18:33 +0200, Geert Jordaens wrote:
Hello,

   I've tried to compile folowing code :

    /*
        valac -o G  --pkg Gee-1.0 G.vala
    */
The package is called gee-1.0, NOT Gee-1.0.

The error you got with .gir files is somewhat surprising to me, but still
the package names are usually lower-case (package name is the name of the
corresponding .pc and .vapi files).


To fix some of the errors with the gir file I changed the valagirparser/valagirwriter
Should I create a bug report for it?


diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 33fd77e..02c913a 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -346,7 +346,7 @@ public class Vala.GIRWriter : CodeVisitor {
         // write prerequisites
         if (iface.get_prerequisites ().size > 0) {
             write_indent ();
-            buffer.append_printf ("<requires>\n");
+            buffer.append_printf ("<prerequisite>\n");
             indent++;

             foreach (DataType base_type in iface.get_prerequisites ()) {
@@ -364,7 +364,7 @@ public class Vala.GIRWriter : CodeVisitor {

             indent--;
             write_indent ();
-            buffer.append_printf ("</requires>\n");
+            buffer.append_printf ("</prerequisite>\n");
         }

         write_annotations (iface);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 11a58c2..87826e1 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -281,7 +281,7 @@ public class Vala.GirParser : CodeVisitor {
         next ();

         string common_prefix = null;
-
+
         while (current_token == MarkupTokenType.START_ELEMENT) {
             if (reader.name == "member") {
                 var ev = parse_enumeration_member ();
@@ -696,8 +696,20 @@ public class Vala.GirParser : CodeVisitor {
         while (current_token == MarkupTokenType.START_ELEMENT) {
             if (reader.name == "prerequisite") {
                 start_element ("prerequisite");
- iface.add_prerequisite (parse_type_from_name (reader.get_attribute ("name")));
                 next ();
+                while (current_token == MarkupTokenType.START_ELEMENT) {
+                    if (reader.name == "object") {
+                        start_element ("object");
+ iface.add_prerequisite (parse_type_from_name (reader.get_attribute ("name")));
+                        next ();
+                        end_element ("object");
+                    } else {
+                        start_element ("interface");
+ iface.add_prerequisite (parse_type_from_name (reader.get_attribute ("name")));
+                        next ();
+                        end_element ("interface");
+                    }
+                }
                 end_element ("prerequisite");
             } else if (reader.name == "field") {
                 parse_field ();
@@ -790,21 +802,29 @@ public class Vala.GirParser : CodeVisitor {
         start_element ("callback");
         string name = reader.get_attribute ("name");
         next ();
-        DataType return_type;
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "return-value") {
-            return_type = parse_return_value ();
-        } else {
+        DataType return_type = null;
+        var parameters = new ArrayList<FormalParameter> ();
+ while (current_token == MarkupTokenType.START_ELEMENT && (reader.name == "return-value" || reader.name == "parameters")) {
+            if (reader.name == "return-value") {
+                return_type = parse_return_value ();
+            } else { /* reader.name == "parameters" */
+                start_element ("parameters");
+                next ();
+                while (current_token == MarkupTokenType.START_ELEMENT) {
+                    parameters.add (parse_parameter ());
+                }
+                end_element ("parameters");
+            }
+        }
+        if (return_type == null) {
             return_type = new VoidType ();
         }
+
+
         var d = new Delegate (name, return_type, get_current_src ());
         d.access = SymbolAccessibility.PUBLIC;
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
-            start_element ("parameters");
-            next ();
-            while (current_token == MarkupTokenType.START_ELEMENT) {
-                d.add_parameter (parse_parameter ());
-            }
-            end_element ("parameters");
+        foreach (FormalParameter param in parameters) {
+            d.add_parameter(param);
         }
         end_element ("callback");
         return d;
@@ -816,8 +836,22 @@ public class Vala.GirParser : CodeVisitor {
         string throws_string = reader.get_attribute ("throws");
         next ();

-        string? ctype;
-        parse_return_value (out ctype);
+        string? ctype=null;
+
+        var parameters = new ArrayList<FormalParameter> ();
+ while (current_token == MarkupTokenType.START_ELEMENT && (reader.name == "return-value" || reader.name == "parameters")) {
+            if (reader.name == "return-value") {
+                parse_return_value (out ctype);
+            } else { /* reader.name == "parameters" */
+                start_element ("parameters");
+                next ();
+                while (current_token == MarkupTokenType.START_ELEMENT) {
+                    parameters.add (parse_parameter ());
+                }
+                end_element ("parameters");
+            }
+        }
+

         var m = new CreationMethod (null, name, get_current_src ());
         m.access = SymbolAccessibility.PUBLIC;
@@ -830,13 +864,9 @@ public class Vala.GirParser : CodeVisitor {
         } else if (m.name.has_prefix ("new_")) {
             m.name = m.name.offset ("new_".len ());
         }
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
-            start_element ("parameters");
-            next ();
-            while (current_token == MarkupTokenType.START_ELEMENT) {
-                m.add_parameter (parse_parameter ());
-            }
-            end_element ("parameters");
+
+        foreach (FormalParameter param in parameters) {
+          m.add_parameter(param);
         }

         if (throws_string == "1") {
@@ -871,12 +901,48 @@ public class Vala.GirParser : CodeVisitor {
         string throws_string = reader.get_attribute ("throws");
         string invoker = reader.get_attribute ("invoker");
         next ();
-        DataType return_type;
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "return-value") {
-            return_type = parse_return_value ();
-        } else {
+        DataType return_type = null;
+        var parameters = new ArrayList<MethodInfo> ();
+        var array_length_parameters = new ArrayList<int> ();
+        var closure_parameters = new ArrayList<int> ();
+        var destroy_parameters = new ArrayList<int> ();
+
+        while (current_token == MarkupTokenType.START_ELEMENT &&
+ (reader.name == "return-value" || reader.name == "parameters")) {
+            if (reader.name == "return-value") {
+                return_type = parse_return_value ();
+            } else { /* reader.name == "parameters" */
+                start_element ("parameters");
+                next ();
+
+                bool first = true;
+                while (current_token == MarkupTokenType.START_ELEMENT) {
+                    int array_length_idx, closure_idx, destroy_idx;
+ var param = parse_parameter (out array_length_idx, out closure_idx, out destroy_idx);
+                    if (array_length_idx != -1) {
+                        array_length_parameters.add (array_length_idx);
+                    }
+                    if (closure_idx != -1) {
+                        closure_parameters.add (closure_idx);
+                    }
+                    if (destroy_idx != -1) {
+                        destroy_parameters.add (destroy_idx);
+                    }
+ // first parameter is instance pointer in virtual methods, ignore
+                    if (element_name != "callback" || !first) {
+ parameters.add (new MethodInfo(param, array_length_idx, closure_idx, destroy_idx));
+                    } else {
+                        first = false;
+                    }
+                }
+                end_element ("parameters");
+            }
+        }
+
+        if (return_type == null) {
             return_type = new VoidType ();
         }
+
         var m = new Method (name, return_type, get_current_src ());
         m.access = SymbolAccessibility.PUBLIC;
         if (cname != null) {
@@ -892,36 +958,6 @@ public class Vala.GirParser : CodeVisitor {
             m.binding = MemberBinding.STATIC;
         }

-        var parameters = new ArrayList<MethodInfo> ();
-        var array_length_parameters = new ArrayList<int> ();
-        var closure_parameters = new ArrayList<int> ();
-        var destroy_parameters = new ArrayList<int> ();
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
-            start_element ("parameters");
-            next ();
-
-            bool first = true;
-            while (current_token == MarkupTokenType.START_ELEMENT) {
-                int array_length_idx, closure_idx, destroy_idx;
- var param = parse_parameter (out array_length_idx, out closure_idx, out destroy_idx);
-                if (array_length_idx != -1) {
-                    array_length_parameters.add (array_length_idx);
-                }
-                if (closure_idx != -1) {
-                    closure_parameters.add (closure_idx);
-                }
-                if (destroy_idx != -1) {
-                    destroy_parameters.add (destroy_idx);
-                }
- // first parameter is instance pointer in virtual methods, ignore
-                if (element_name != "callback" || !first) {
- parameters.add (new MethodInfo(param, array_length_idx, closure_idx, destroy_idx));
-                } else {
-                    first = false;
-                }
-            }
-            end_element ("parameters");
-        }
         int i = 0, j=1, add=0;

if (element_name == "method" || element_name == "virtual-method" || element_name == "callback") {
@@ -932,8 +968,8 @@ public class Vala.GirParser : CodeVisitor {
         int last = -1;
         foreach (MethodInfo info in parameters) {
             if (!array_length_parameters.contains (i+add)
- && !closure_parameters.contains (i+add)
- && !destroy_parameters.contains (i+add)) {
+ && !closure_parameters.contains (i+add)
+ && !destroy_parameters.contains (i+add)) {
                 info.vala_idx = (float) j;
                 info.keep = true;

@@ -943,7 +979,7 @@ public class Vala.GirParser : CodeVisitor {
                     last_idx = parameters[last].vala_idx;
                 }
                 for (int k=last+1; k < i; k++) {
- parameters[k].vala_idx = last_idx + (((j - last_idx) / (i-last)) * (k-last)); + parameters[k].vala_idx = last_idx + (((j - last_idx) / (i-last)) * (k-last));
                 }
                 last = i+1;
                 j++;
@@ -1101,7 +1137,7 @@ public class Vala.GirParser : CodeVisitor {
             try {
                 string metadata;
FileUtils.get_contents (metadata_filename, out metadata, null);
-
+
                 foreach (string line in metadata.split ("\n")) {
                     if (line.has_prefix ("#")) {
                         // ignore comment lines



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