From: Juerg Billeter Date: Sat, 15 Dec 2007 07:57:03 +0000 (+0000) Subject: refactor collection type check X-Git-Tag: VALA_0_1_6~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ff63ef87061c97da1214d863f67fd99f321acfd;p=platform%2Fupstream%2Fvala.git refactor collection type check 2007-12-15 Juerg Billeter * vala/valadatatype.vala, vala/valasemanticanalyzer.vala: refactor collection type check svn path=/trunk/; revision=772 --- diff --git a/ChangeLog b/ChangeLog index 14a3cb6..05ff946 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-12-15 Jürg Billeter + * vala/valadatatype.vala, vala/valasemanticanalyzer.vala: refactor + collection type check + +2007-12-15 Jürg Billeter + * vala/valadatatype.vala, vala/valasemanticanalyzer.vala, vapi/glib-2.0.vapi: move is_type_compatible method from SemanticAnalyzer to DataType diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 3559c09..9569db5 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -441,6 +441,10 @@ public class Vala.DataType : CodeNode { type_parameter != null; } + public virtual bool is_array () { + return data_type is Array; + } + /** * Returns a list of symbols that define this type. * diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 2821e06..fe4e7b9 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -54,10 +54,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor { Typesymbol pointer_type; Typesymbol object_type; Typesymbol initially_unowned_type; - Typesymbol glist_type; - Typesymbol gslist_type; + DataType glist_type; + DataType gslist_type; Typesymbol gerror_type; - Typesymbol iterable_type; + DataType iterable_type; Typesymbol iterator_type; Typesymbol list_type; Typesymbol map_type; @@ -102,15 +102,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor { type_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Type")); - glist_type = (Typesymbol) glib_ns.scope.lookup ("List"); - gslist_type = (Typesymbol) glib_ns.scope.lookup ("SList"); + glist_type = new ReferenceType ((Typesymbol) glib_ns.scope.lookup ("List")); + gslist_type = new ReferenceType ((Typesymbol) glib_ns.scope.lookup ("SList")); gerror_type = (Typesymbol) glib_ns.scope.lookup ("Error"); } var gee_ns = root_symbol.scope.lookup ("Gee"); if (gee_ns != null) { - iterable_type = (Typesymbol) gee_ns.scope.lookup ("Iterable"); + iterable_type = new ReferenceType ((Typesymbol) gee_ns.scope.lookup ("Iterable")); iterator_type = (Typesymbol) gee_ns.scope.lookup ("Iterator"); list_type = (Typesymbol) gee_ns.scope.lookup ("List"); map_type = (Typesymbol) gee_ns.scope.lookup ("Map"); @@ -909,8 +909,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { stmt.add_local_variable (stmt.collection_variable_declarator); stmt.collection_variable_declarator.active = true; - var collection_type = stmt.collection.static_type.data_type; - if (iterable_type != null && collection_type.is_subtype_of (iterable_type)) { + var collection_type = stmt.collection.static_type; + if (iterable_type != null && collection_type.compatible (iterable_type)) { stmt.iterator_variable_declarator = new VariableDeclarator ("%s_it".printf (stmt.variable_name)); stmt.iterator_variable_declarator.type_reference = new ReferenceType (iterator_type); stmt.iterator_variable_declarator.type_reference.takes_ownership = true; @@ -918,7 +918,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { stmt.add_local_variable (stmt.iterator_variable_declarator); stmt.iterator_variable_declarator.active = true; - } else if (!(collection_type is Array || collection_type == glist_type || collection_type == gslist_type)) { + } else if (!(collection_type.is_array () || collection_type.compatible (glist_type) || collection_type.compatible (gslist_type))) { stmt.error = true; Report.error (stmt.source_reference, "Collection not iterable"); return;