From: Juerg Billeter Date: Sat, 1 Sep 2007 13:12:28 +0000 (+0000) Subject: let DataType.is_subtype_of return true if the specified type is the same X-Git-Tag: VALA_0_1_4~84 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d63ccdc1ef217e88f4d8478a2743a238e3dd83b;p=platform%2Fupstream%2Fvala.git let DataType.is_subtype_of return true if the specified type is the same 2007-09-01 Juerg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index 8c3e6d4..f67782e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-09-01 Jürg Billeter + * 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 + * doc/vala/types.xml: add introduction to data types 2007-09-01 Jürg Billeter diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 2670577..95b28a9 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -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 get_params = get_method.get_parameters (); Iterator get_params_it = get_params.iterator (); diff --git a/gobject/valacodegeneratorassignment.vala b/gobject/valacodegeneratorassignment.vala index c42b3c9..292ab0c 100644 --- a/gobject/valacodegeneratorassignment.vala +++ b/gobject/valacodegeneratorassignment.vala @@ -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 set_params = set_method.get_parameters (); Iterator set_params_it = set_params.iterator (); diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 627aebc..b38f8e4 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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; } } diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index b87c02e..0862855 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -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); } /** diff --git a/vala/valainterface.vala b/vala/valainterface.vala index ce2b8d5..2a17312 100644 --- a/vala/valainterface.vala +++ b/vala/valainterface.vala @@ -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; } } diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index dfc7eff..d6a8bbc 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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 indices = expr.get_indices (); if (indices.size != 1) { expr.error = true;