let DataType.is_subtype_of return true if the specified type is the same
authorJuerg Billeter <j@bitron.ch>
Sat, 1 Sep 2007 13:12:28 +0000 (13:12 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 1 Sep 2007 13:12:28 +0000 (13:12 +0000)
2007-09-01  Juerg Billeter  <j@bitron.ch>

* vala/valaclass.vala, vala/valadatatype.vala, vala/valainterface.vala,
  vala/valasemanticanalyzer.vala, gobject/valacodegenerator.vala,
  gobject/valacodegeneratorassignment.vala: let DataType.is_subtype_of
  return true if the specified type is the same

svn path=/trunk/; revision=564

ChangeLog
gobject/valacodegenerator.vala
gobject/valacodegeneratorassignment.vala
vala/valaclass.vala
vala/valadatatype.vala
vala/valainterface.vala
vala/valasemanticanalyzer.vala

index 8c3e6d4..f67782e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2007-09-01  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valaclass.vala, vala/valadatatype.vala, vala/valainterface.vala,
+         vala/valasemanticanalyzer.vala, gobject/valacodegenerator.vala,
+         gobject/valacodegeneratorassignment.vala: let DataType.is_subtype_of
+         return true if the specified type is the same
+
+2007-09-01  Jürg Billeter  <j@bitron.ch>
+
        * doc/vala/types.xml: add introduction to data types
 
 2007-09-01  Jürg Billeter  <j@bitron.ch>
index 2670577..95b28a9 100644 (file)
@@ -1564,8 +1564,7 @@ public class Vala.CodeGenerator : CodeVisitor {
 
                        cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier (it_name), new CCodeMemberAccess.pointer (new CCodeIdentifier (it_name), "next")));
                        cblock.add_statement (cfor);
-               } else if (stmt.collection.static_type.data_type == iterable_type ||
-                          stmt.collection.static_type.data_type.is_subtype_of (iterable_type)) {
+               } else if (stmt.collection.static_type.data_type.is_subtype_of (iterable_type)) {
                        var it_name = "%s_it".printf (stmt.variable_name);
 
                        var citdecl = new CCodeDeclaration (iterator_type.get_cname () + "*");
@@ -2154,8 +2153,7 @@ public class Vala.CodeGenerator : CodeVisitor {
 
                        expr.ccodenode = ccall;
                } else if (container_type != null && list_type != null && map_type != null &&
-                          (container_type == list_type || container_type.is_subtype_of (list_type) ||
-                           container_type == map_type || container_type.is_subtype_of (map_type))) {
+                          (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
                        var get_method = (Method) container_type.scope.lookup ("get");
                        Collection<FormalParameter> get_params = get_method.get_parameters ();
                        Iterator<FormalParameter> get_params_it = get_params.iterator ();
index c42b3c9..292ab0c 100644 (file)
@@ -284,8 +284,7 @@ public class Vala.CodeGenerator {
                        var cindex = (CCodeExpression) indices_it.get ().ccodenode;
 
                        if (container_type != null && list_type != null && map_type != null &&
-                           (container_type == list_type || container_type.is_subtype_of (list_type) ||
-                            container_type == map_type || container_type.is_subtype_of (map_type))) {
+                           (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
                                var set_method = (Method) container_type.scope.lookup ("set");
                                Collection<FormalParameter> set_params = set_method.get_parameters ();
                                Iterator<FormalParameter> set_params_it = set_params.iterator ();
index 627aebc..b38f8e4 100644 (file)
@@ -553,9 +553,12 @@ public class Vala.Class : DataType {
        }
        
        public override bool is_subtype_of (DataType! t) {
+               if (this == t) {
+                       return true;
+               }
+
                foreach (TypeReference base_type in base_types) {
-                       if (base_type.data_type == t ||
-                           base_type.data_type.is_subtype_of (t)) {
+                       if (base_type.data_type.is_subtype_of (t)) {
                                return true;
                        }
                }
index b87c02e..0862855 100644 (file)
@@ -254,14 +254,14 @@ public abstract class Vala.DataType : Symbol {
        }
 
        /**
-        * Checks whether this data type is a subtype of the specified data
-        * type.
+        * Checks whether this data type is equal to or a subtype of the
+        * specified data type.
         *
         * @param t a data type
         * @return  true if t is a supertype of this data type, false otherwise
         */
        public virtual bool is_subtype_of (DataType! t) {
-               return false;
+               return (this == t);
        }
        
        /**
index ce2b8d5..2a17312 100644 (file)
@@ -291,9 +291,12 @@ public class Vala.Interface : DataType {
        }
 
        public override bool is_subtype_of (DataType! t) {
+               if (this == t) {
+                       return true;
+               }
+
                foreach (TypeReference prerequisite in prerequisites) {
-                       if (prerequisite.data_type == t ||
-                           prerequisite.data_type.is_subtype_of (t)) {
+                       if (prerequisite.data_type.is_subtype_of (t)) {
                                return true;
                        }
                }
index dfc7eff..d6a8bbc 100644 (file)
@@ -886,7 +886,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                stmt.collection_variable_declarator.active = true;
 
                var collection_type = stmt.collection.static_type.data_type;
-               if (iterable_type != null && (collection_type == iterable_type || collection_type.is_subtype_of (iterable_type))) {
+               if (iterable_type != null && collection_type.is_subtype_of (iterable_type)) {
                        stmt.iterator_variable_declarator = new VariableDeclarator ("%s_it".printf (stmt.variable_name));
                        stmt.iterator_variable_declarator.type_reference = new TypeReference ();
                        stmt.iterator_variable_declarator.type_reference.data_type = iterator_type;
@@ -1733,8 +1733,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
                        expr.static_type = unichar_type;
                } else if (container_type != null && list_type != null && map_type != null &&
-                          (container_type == list_type || container_type.is_subtype_of (list_type) ||
-                           container_type == map_type || container_type.is_subtype_of (map_type))) {
+                          (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
                        Collection<Expression> indices = expr.get_indices ();
                        if (indices.size != 1) {
                                expr.error = true;