]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Transform Struct.*_rank() methods into "rank" property 3158ae7a0f990b44f114d51498636e669609af0d
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 26 Apr 2018 07:33:58 +0000 (09:33 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 26 Apr 2018 07:33:58 +0000 (09:33 +0200)
vala/valadatatype.vala
vala/valasemanticanalyzer.vala
vala/valastruct.vala
vapigen/valagidlparser.vala

index 1bbbc82b6dcbdefd3813d80f9a2b2fceb7ab2fed..e25e5a4173ed9bb2197241e69cf2ba1125d43ad3 100644 (file)
@@ -336,7 +336,7 @@ public abstract class Vala.DataType : CodeNode {
 
                        if ((expr_struct.is_integer_type () && expect_struct.is_integer_type ()) ||
                            (expr_struct.is_floating_type () && expect_struct.is_floating_type ())) {
-                               if (expr_struct.get_rank () <= expect_struct.get_rank ()) {
+                               if (expr_struct.rank <= expect_struct.rank) {
                                        return true;
                                }
                        }
index 73b0b61efbe0b0dc61b3391e8fb81f3a207850e3..8f4335bd2cd2d3582479529a89f67d7399c55cfa 100644 (file)
@@ -991,7 +991,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
                if (left.is_floating_type () == right.is_floating_type ()) {
                        // both operands integer or floating type
-                       if (left.get_rank () >= right.get_rank ()) {
+                       if (left.rank >= right.rank) {
                                return left_type;
                        } else {
                                return right_type;
index 972b4bdab10f896990d5ac8d7a4ca7678a6b862a..23c005363704b5459713f871c0fb481a5431be81 100644 (file)
@@ -38,7 +38,7 @@ public class Vala.Struct : TypeSymbol {
        private bool? floating_type;
        private bool? decimal_floating_type;
        private bool? simple_type;
-       private int? rank;
+       private int? _rank;
        private int? _width;
        private bool? _signed;
        private bool? _is_immutable;
@@ -124,6 +124,37 @@ public class Vala.Struct : TypeSymbol {
                }
        }
 
+       /**
+        * Specifies the rank of this integer or floating point type.
+        */
+       public int rank {
+               get {
+                       if (_rank == null) {
+                               if (is_integer_type () && has_attribute_argument ("IntegerType", "rank")) {
+                                       _rank = get_attribute_integer ("IntegerType", "rank");
+                               } else if (has_attribute_argument ("FloatingType", "rank")) {
+                                       _rank = get_attribute_integer ("FloatingType", "rank");
+                               } else {
+                                       var st = base_struct;
+                                       if (st != null) {
+                                               _rank = st.rank;
+                                       } else {
+                                               Report.error (source_reference, "internal error: struct has no rank");
+                                       }
+                               }
+                       }
+                       return _rank;
+               }
+               set {
+                       _rank = value;
+                       if (is_integer_type ()) {
+                               set_attribute_integer ("IntegerType", "rank", _rank);
+                       } else {
+                               set_attribute_integer ("FloatingType", "rank", _rank);
+                       }
+               }
+       }
+
        /**
         * Creates a new struct.
         *
@@ -353,39 +384,6 @@ public class Vala.Struct : TypeSymbol {
                return decimal_floating_type;
        }
 
-       /**
-        * Returns the rank of this integer or floating point type.
-        *
-        * @return the rank if this is an integer or floating point type
-        */
-       public int get_rank () {
-               if (rank == null) {
-                       if (is_integer_type () && has_attribute_argument ("IntegerType", "rank")) {
-                               rank = get_attribute_integer ("IntegerType", "rank");
-                       } else if (has_attribute_argument ("FloatingType", "rank")) {
-                               rank = get_attribute_integer ("FloatingType", "rank");
-                       } else {
-                               var st = base_struct;
-                               if (st != null) {
-                                       rank = st.get_rank ();
-                               }
-                       }
-               }
-               return rank;
-       }
-
-       /**
-        * Sets the rank of this integer or floating point type.
-        */
-       public void set_rank (int rank) {
-               this.rank = rank;
-               if (is_integer_type ()) {
-                       set_attribute_integer ("IntegerType", "rank", rank);
-               } else {
-                       set_attribute_integer ("FloatingType", "rank", rank);
-               }
-       }
-
        public override int get_type_parameter_index (string name) {
                int i = 0;
 
index bb3c4bb866582d4c6a54fbd7f8428cccf65df459..e0ffca52b1eedaf983d2b97a66eb60e3d76458a1 100644 (file)
@@ -799,7 +799,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                                } else if (nv[0] == "base_type") {
                                                        st.base_type = parse_type_string (eval (nv[1]));
                                                } else if (nv[0] == "rank") {
-                                                       st.set_rank (int.parse (eval (nv[1])));
+                                                       st.rank = int.parse (eval (nv[1]));
                                                } else if (nv[0] == "simple_type") {
                                                        if (eval (nv[1]) == "1") {
                                                                st.set_simple_type (true);