~ubuntu-branches/ubuntu/maverick/vala/maverick

« back to all changes in this revision

Viewing changes to vapigen/valagidlparser.vala

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-04-02 10:10:55 UTC
  • mfrom: (1.4.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402101055-qbx3okzv0tnp3wpp
Tags: 0.8.0-0ubuntu1
* New upstream release:
  - Infer type arguments when calling generic methods.
  - Support `in' operator for arrays.
  - Add experimental support for regular expression literals.
  - Add experimental support for chained relational expressions.
  - Add va_list support.
  - Add clutter-gtk-0.10 bindings (Gordon Allott).
  - Add gdl-1.0 bindings (Nicolas Joseph).
  - Add gstreamer-app-0.10 bindings (Sebastian Dröge).
  - Add gstreamer-cdda-0.10 bindings (Sebastian Dröge).
  - Add gudev-1.0 bindings (Jim Nelson).
  - Add libgda-report-4.0 bindings (Shawn Ferris).
  - Add libgvc (graphviz) bindings (Martin Olsson).
  - Add purple bindings (Adrien Bustany).
  - Many bug fixes and binding updates.
* debian/patches/99_ltmain_as-needed.patch: refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
376
376
                                                        if (eval (nv[1]) == "1") {
377
377
                                                                param_type.nullable = true;
378
378
                                                        }
 
379
                                                } else if (nv[0] == "type_arguments") {
 
380
                                                        var type_args = eval (nv[1]).split (",");
 
381
                                                        foreach (string type_arg in type_args) {
 
382
                                                                param_type.add_type_argument (get_type_from_string (type_arg));
 
383
                                                        }
 
384
                                                } else if (nv[0] == "no_array_length") {
 
385
                                                        if (eval (nv[1]) == "1") {
 
386
                                                                p.no_array_length = true;
 
387
                                                        }
379
388
                                                }
380
389
                                        }
381
390
                                }
1462
1471
                
1463
1472
                return type;
1464
1473
        }
1465
 
        
 
1474
 
 
1475
        public DataType get_type_from_string (string type_arg) {
 
1476
                bool is_unowned = false;
 
1477
                UnresolvedSymbol? sym = null;
 
1478
 
 
1479
                if (type_arg == "pointer") {
 
1480
                        return new PointerType (new VoidType ());
 
1481
                }
 
1482
 
 
1483
                if (type_arg.has_prefix ("unowned ")) {
 
1484
                        type_arg = type_arg.offset ("unowned ".len ());
 
1485
                        is_unowned = true;
 
1486
                }
 
1487
 
 
1488
                foreach (unowned string s in type_arg.split (".")) {
 
1489
                        sym = new UnresolvedSymbol (sym, s);
 
1490
                }
 
1491
 
 
1492
                var arg_type = new UnresolvedType.from_symbol (sym);
 
1493
                arg_type.value_owned = !is_unowned;
 
1494
 
 
1495
                return arg_type;
 
1496
        }
 
1497
 
1466
1498
        private Method? create_method (string name, string symbol, IdlNodeParam? res, GLib.List<IdlNodeParam>? parameters, bool is_constructor, bool is_interface) {
1467
1499
                DataType return_type = null;
1468
1500
                if (res != null) {
1570
1602
                                } else if (nv[0] == "type_arguments") {
1571
1603
                                        var type_args = eval (nv[1]).split (",");
1572
1604
                                        foreach (string type_arg in type_args) {
1573
 
                                                var arg_type = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, type_arg));
1574
 
                                                arg_type.value_owned = true;
1575
 
                                                return_type.add_type_argument (arg_type);
 
1605
                                                return_type.add_type_argument (get_type_from_string (type_arg));
1576
1606
                                        }
1577
1607
                                } else if (nv[0] == "cheader_filename") {
1578
1608
                                        m.add_cheader_filename (eval (nv[1]));
1660
1690
                        bool set_delegate_target_pos = false;
1661
1691
                        double delegate_target_pos = 0;
1662
1692
                        bool array_requested = false;
 
1693
                        bool out_requested = false;
1663
1694
                        attributes = get_attributes ("%s.%s".printf (symbol, param_node.name));
1664
1695
                        if (attributes != null) {
1665
1696
                                foreach (string attr in attributes) {
1668
1699
                                                if (eval (nv[1]) == "1") {
1669
1700
                                                        param_type = new ArrayType (param_type, 1, param_type.source_reference);
1670
1701
                                                        p.parameter_type = param_type;
1671
 
                                                        p.direction = ParameterDirection.IN;
 
1702
                                                        if (!out_requested) {
 
1703
                                                                p.direction = ParameterDirection.IN;
 
1704
                                                        }
1672
1705
                                                        array_requested = true;
1673
1706
                                                }
1674
1707
                                        } else if (nv[0] == "is_out") {
1675
1708
                                                if (eval (nv[1]) == "1") {
1676
1709
                                                        p.direction = ParameterDirection.OUT;
 
1710
                                                        out_requested = true;
1677
1711
                                                        if (!array_requested && param_type is ArrayType) {
1678
1712
                                                                var array_type = (ArrayType) param_type;
1679
1713
                                                                param_type = array_type.element_type;
1735
1769
                                        } else if (nv[0] == "type_arguments") {
1736
1770
                                                var type_args = eval (nv[1]).split (",");
1737
1771
                                                foreach (string type_arg in type_args) {
1738
 
                                                        var arg_type = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, type_arg));
1739
 
                                                        arg_type.value_owned = true;
1740
 
                                                        param_type.add_type_argument (arg_type);
 
1772
                                                        param_type.add_type_argument (get_type_from_string (type_arg));
 
1773
                                                }
 
1774
                                        } else if (nv[0] == "default_value") {
 
1775
                                                var val = eval (nv[1]);
 
1776
                                                if (val == "null") {
 
1777
                                                        p.default_expression = new NullLiteral (param_type.source_reference);
 
1778
                                                } else if (val == "true") {
 
1779
                                                        p.default_expression = new BooleanLiteral (true, param_type.source_reference);
 
1780
                                                } else if (val == "false") {
 
1781
                                                        p.default_expression = new BooleanLiteral (false, param_type.source_reference);
 
1782
                                                } else {
 
1783
                                                        unowned string endptr;
 
1784
                                                        unowned string val_end = val.offset (val.len ());
 
1785
 
 
1786
                                                        val.to_long (out endptr);
 
1787
                                                        if ((long)endptr == (long)val_end) {
 
1788
                                                                p.default_expression = new IntegerLiteral (val, param_type.source_reference);
 
1789
                                                        } else {
 
1790
                                                                val.to_double (out endptr);
 
1791
                                                                if ((long)endptr == (long)val_end) {
 
1792
                                                                        p.default_expression = new RealLiteral (val, param_type.source_reference);
 
1793
                                                                } else {
 
1794
                                                                        p.default_expression = new StringLiteral ("\"%s\"".printf (val), param_type.source_reference);
 
1795
                                                                }
 
1796
                                                        }
1741
1797
                                                }
1742
1798
                                        }
1743
1799
                                }
1909
1965
                                } else if (nv[0] == "type_arguments") {
1910
1966
                                        var type_args = eval (nv[1]).split (",");
1911
1967
                                        foreach (string type_arg in type_args) {
1912
 
                                                var arg_type = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, type_arg));
1913
 
                                                arg_type.value_owned = true;
1914
 
                                                prop.property_type.add_type_argument (arg_type);
 
1968
                                                prop.property_type.add_type_argument (get_type_from_string (type_arg));
1915
1969
                                        }
1916
1970
                                } else if (nv[0] == "accessor_method") {
1917
1971
                                        if (eval (nv[1]) == "0") {
1973
2027
 
1974
2028
                string cheader_filename = null;
1975
2029
                string ctype = null;
 
2030
                string array_length_cname = null;
 
2031
                string array_length_type = null;
1976
2032
                bool array_null_terminated = false;
1977
2033
 
1978
2034
                var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
1994
2050
                                                type.value_owned = true;
1995
2051
                                        }
1996
2052
                                } else if (nv[0] == "type_name") {
1997
 
                                        ((UnresolvedType) type).unresolved_symbol = new UnresolvedSymbol (null, eval (nv[1]));
 
2053
                                        if (eval (nv[1]) == "pointer") {
 
2054
                                                type = new PointerType (new VoidType ());
 
2055
                                        } else {
 
2056
                                                var unresolved_sym = new UnresolvedSymbol (null, eval (nv[1]));
 
2057
                                                if (type is ArrayType) {
 
2058
                                                        ((UnresolvedType) ((ArrayType) type).element_type).unresolved_symbol = unresolved_sym;
 
2059
                                                } else {
 
2060
                                                        ((UnresolvedType) type).unresolved_symbol = unresolved_sym;
 
2061
                                                }
 
2062
                                        }
1998
2063
                                } else if (nv[0] == "type_arguments") {
1999
2064
                                        var type_args = eval (nv[1]).split (",");
2000
2065
                                        foreach (string type_arg in type_args) {
2001
 
                                                var arg_type = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, type_arg));
2002
 
                                                arg_type.value_owned = true;
2003
 
                                                type.add_type_argument (arg_type);
 
2066
                                                type.add_type_argument (get_type_from_string (type_arg));
2004
2067
                                        }
2005
2068
                                } else if (nv[0] == "cheader_filename") {
2006
2069
                                        cheader_filename = eval (nv[1]);
2010
2073
                                        if (eval (nv[1]) == "1") {
2011
2074
                                                array_null_terminated = true;
2012
2075
                                        }
 
2076
                                } else if (nv[0] == "array_length_cname") {
 
2077
                                        array_length_cname = eval (nv[1]);
 
2078
                                } else if (nv[0] == "array_length_type") {
 
2079
                                        array_length_type = eval (nv[1]);
2013
2080
                                }
2014
2081
                        }
2015
2082
                }
2043
2110
                        field.add_cheader_filename (cheader_filename);
2044
2111
                }
2045
2112
 
2046
 
                field.no_array_length = true;
2047
2113
                if (array_null_terminated) {
2048
2114
                        field.array_null_terminated = true;
2049
2115
                }
2050
2116
 
 
2117
                if (array_length_cname != null || array_length_type != null) {
 
2118
                        if (array_length_cname != null) {
 
2119
                                field.set_array_length_cname (array_length_cname);
 
2120
                        }
 
2121
                        if (array_length_type != null) {
 
2122
                                field.array_length_type = array_length_type;
 
2123
                        }
 
2124
                } else {
 
2125
                        field.no_array_length = true;
 
2126
                }
 
2127
 
2051
2128
                return field;
2052
2129
        }
2053
2130
 
2076
2153
                if (attributes == null) {
2077
2154
                        return null;
2078
2155
                }
2079
 
                
2080
 
                return attributes.split (" ");
 
2156
 
 
2157
                GLib.SList<string> attr_list = new GLib.SList<string> ();
 
2158
                var attr = new GLib.StringBuilder.sized (attributes.size ());
 
2159
                var attributes_len = attributes.len ();
 
2160
                unowned string remaining = attributes;
 
2161
                bool quoted = false, escaped = false;
 
2162
                for (int b = 0 ; b < attributes_len ; b++) {
 
2163
                        unichar c = remaining.get_char ();
 
2164
 
 
2165
                        if (escaped) {
 
2166
                                escaped = false;
 
2167
                                attr.append_unichar (c);
 
2168
                        } else {
 
2169
                                if (c == '"') {
 
2170
                                        attr.append_unichar (c);
 
2171
                                        quoted = !quoted;
 
2172
                                } else if (c == '\\') {
 
2173
                                        escaped = true;
 
2174
                                } else if (!quoted && (c == ' ')) {
 
2175
                                        attr_list.prepend (attr.str);
 
2176
                                        attr.truncate (0);
 
2177
                                } else {
 
2178
                                        attr.append_unichar (c);
 
2179
                                }
 
2180
                        }
 
2181
 
 
2182
                        remaining = remaining.offset (1);
 
2183
                }
 
2184
 
 
2185
                if (attr.len > 0) {
 
2186
                        attr_list.prepend (attr.str);
 
2187
                }
 
2188
 
 
2189
                var attrs = new string[attr_list.length ()];
 
2190
                unowned GLib.SList<string>? attr_i = attr_list;
 
2191
                for (int a = 0 ; a < attrs.length ; a++, attr_i = attr_i.next) {
 
2192
                        attrs[(attrs.length - 1) - a] = attr_i.data;
 
2193
                }
 
2194
 
 
2195
                return attrs;
2081
2196
        }
2082
2197
        
2083
2198
        private string eval (string s) {