Commit 7d63ccdc authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

let DataType.is_subtype_of return true if the specified type is the same

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
parent 72ba2cfa
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
......
......@@ -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 ();
......
......@@ -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 ();
......
......@@ -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;
}
}
......
......@@ -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);
}
/**
......
......@@ -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;
}
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment