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>
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 () + "*");
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 ();
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 ();
}
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;
}
}
}
/**
- * 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);
}
/**
}
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;
}
}
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;
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;