Commit 4f0849ec authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Replace ClassInstanceType and InterfaceInstanceType by ObjectType

2008-05-26  Juerg Billeter  <j@bitron.ch>

	* vala/Makefile.am:
	* vala/valaclass.vala:
	* vala/valainterface.vala:
	* vala/valaobjecttype.vala:
	* vala/valasemanticanalyzer.vala:
	* vala/valasignal.vala:
	* vala/valasymbolresolver.vala:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodememberaccessbinding.vala:
	* gobject/valaccodemethodbinding.vala:
	* gobject/valagidlwriter.vala:

	Replace ClassInstanceType and InterfaceInstanceType by ObjectType

svn path=/trunk/; revision=1447
parent 83e85d09
2008-05-26 Jürg Billeter <j@bitron.ch>
* vala/Makefile.am:
* vala/valaclass.vala:
* vala/valainterface.vala:
* vala/valaobjecttype.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasignal.vala:
* vala/valasymbolresolver.vala:
* gobject/valaccodegenerator.vala:
* gobject/valaccodememberaccessbinding.vala:
* gobject/valaccodemethodbinding.vala:
* gobject/valagidlwriter.vala:
Replace ClassInstanceType and InterfaceInstanceType by ObjectType
2008-05-26 Jamie McCracken <jamiemcc@gnome.org>
* vala/valagenieparser.vala:
......@@ -23,7 +39,6 @@
* vala/valgenieparser.vala: replaced foreach with for..in
2008-05-26 Jürg Billeter <j@bitron.ch>
* vapi/tiff.vapi: more fixes, patch by Christian Meyer
......
......@@ -221,7 +221,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
uint64_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("uint64"));
float_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("float"));
double_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("double"));
string_type = new ClassInstanceType ((Class) root_symbol.scope.lookup ("string"));
string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
substring_method = (Method) string_type.data_type.scope.lookup ("substring");
var glib_ns = root_symbol.scope.lookup ("GLib");
......@@ -771,9 +771,9 @@ public class Vala.CCodeGenerator : CodeGenerator {
ReferenceType this_type;
if (t is Class) {
this_type = new ClassInstanceType ((Class) t);
this_type = new ObjectType ((Class) t);
} else {
this_type = new InterfaceInstanceType ((Interface) t);
this_type = new ObjectType ((Interface) t);
}
var cselfparam = new CCodeFormalParameter ("self", this_type.get_cname ());
var value_type = prop.property_type.copy ();
......@@ -1987,7 +1987,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier (it_name), new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier (it_name), new CCodeConstant ("1"))));
cblock.add_statement (cfor);
}
} else if (stmt.collection.value_type.compatible (new ClassInstanceType (glist_type)) || stmt.collection.value_type.compatible (new ClassInstanceType (gslist_type))) {
} else if (stmt.collection.value_type.compatible (new ObjectType (glist_type)) || stmt.collection.value_type.compatible (new ObjectType (gslist_type))) {
var it_name = "%s_it".printf (stmt.variable_name);
var citdecl = new CCodeDeclaration (collection_type.get_cname ());
......@@ -2039,7 +2039,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier (it_name), new CCodeMemberAccess.pointer (new CCodeIdentifier (it_name), "next")));
cblock.add_statement (cfor);
} else if (iterable_type != null && stmt.collection.value_type.compatible (new InterfaceInstanceType (iterable_type))) {
} else if (iterable_type != null && stmt.collection.value_type.compatible (new ObjectType (iterable_type))) {
var it_name = "%s_it".printf (stmt.variable_name);
var citdecl = new CCodeDeclaration (iterator_type.get_cname () + "*");
......@@ -3715,9 +3715,9 @@ public class Vala.CCodeGenerator : CodeGenerator {
DataType type = null;
if (sym is Class) {
type = new ClassInstanceType ((Class) sym);
type = new ObjectType ((Class) sym);
} else if (sym is Interface) {
type = new InterfaceInstanceType ((Interface) sym);
type = new ObjectType ((Interface) sym);
} else if (sym is Struct) {
type = new ValueType ((Struct) sym);
} else if (sym is Enum) {
......
......@@ -254,9 +254,9 @@ public class Vala.CCodeMemberAccessBinding : CCodeExpressionBinding {
if (codegen.current_type_symbol != null) {
/* base type is available if this is a type method */
if (codegen.current_type_symbol is Class) {
base_type = new ClassInstanceType ((Class) codegen.current_type_symbol);
base_type = new ObjectType ((Class) codegen.current_type_symbol);
} else if (codegen.current_type_symbol is Interface) {
base_type = new InterfaceInstanceType ((Interface) codegen.current_type_symbol);
base_type = new ObjectType ((Interface) codegen.current_type_symbol);
} else {
base_type = new ValueType (codegen.current_type_symbol);
pub_inst = new CCodeIdentifier ("(*self)");
......
......@@ -70,7 +70,7 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
}
if (cl != null) {
creturn_type = new ClassInstanceType (cl);
creturn_type = new ObjectType (cl);
}
}
......@@ -142,19 +142,19 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
Typesymbol parent_type = find_parent_type (m);
DataType this_type;
if (parent_type is Class) {
this_type = new ClassInstanceType ((Class) parent_type);
this_type = new ObjectType ((Class) parent_type);
} else if (parent_type is Interface) {
this_type = new InterfaceInstanceType ((Interface) parent_type);
this_type = new ObjectType ((Interface) parent_type);
} else {
this_type = new ValueType (parent_type);
}
CCodeFormalParameter instance_param = null;
if (m.base_interface_method != null && !m.is_abstract && !m.is_virtual) {
var base_type = new InterfaceInstanceType ((Interface) m.base_interface_method.parent_symbol);
var base_type = new ObjectType ((Interface) m.base_interface_method.parent_symbol);
instance_param = new CCodeFormalParameter ("base", base_type.get_cname ());
} else if (m.overrides) {
var base_type = new ClassInstanceType ((Class) m.base_method.parent_symbol);
var base_type = new ObjectType ((Class) m.base_method.parent_symbol);
instance_param = new CCodeFormalParameter ("base", base_type.get_cname ());
} else {
if (m.parent_symbol is Struct && !((Struct) m.parent_symbol).is_simple_type ()) {
......@@ -228,12 +228,12 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
ReferenceType base_expression_type;
if (m.overrides) {
base_method = m.base_method;
base_expression_type = new ClassInstanceType ((Class) base_method.parent_symbol);
base_expression_type = new ObjectType ((Class) base_method.parent_symbol);
} else {
base_method = m.base_interface_method;
base_expression_type = new InterfaceInstanceType ((Interface) base_method.parent_symbol);
base_expression_type = new ObjectType ((Interface) base_method.parent_symbol);
}
var self_target_type = new ClassInstanceType (cl);
var self_target_type = new ObjectType (cl);
CCodeExpression cself = codegen.get_implicit_cast_expression (new CCodeIdentifier ("base"), base_expression_type, self_target_type);
var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
......@@ -369,9 +369,9 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
ReferenceType this_type;
if (m.parent_symbol is Class) {
this_type = new ClassInstanceType ((Class) m.parent_symbol);
this_type = new ObjectType ((Class) m.parent_symbol);
} else {
this_type = new InterfaceInstanceType ((Interface) m.parent_symbol);
this_type = new ObjectType ((Interface) m.parent_symbol);
}
cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
......
......@@ -105,8 +105,8 @@ public class Vala.GIdlWriter : CodeVisitor {
// write implemented interfaces
bool first = true;
foreach (DataType base_type in cl.get_base_types ()) {
var iface_type = base_type as InterfaceInstanceType;
if (iface_type != null) {
var object_type = (ObjectType) base_type;
if (object_type.type_symbol is Interface) {
if (first) {
write_indent ();
stream.printf ("<implements>\n");
......@@ -114,7 +114,7 @@ public class Vala.GIdlWriter : CodeVisitor {
first = false;
}
write_indent ();
stream.printf ("<interface name=\"%s\"/>\n", iface_type.interface_symbol.get_full_name ());
stream.printf ("<interface name=\"%s\"/>\n", object_type.type_symbol.get_full_name ());
}
}
if (!first) {
......@@ -185,14 +185,13 @@ public class Vala.GIdlWriter : CodeVisitor {
indent++;
foreach (DataType base_type in iface.get_prerequisites ()) {
var class_type = base_type as ClassInstanceType;
var iface_type = base_type as InterfaceInstanceType;
if (class_type != null) {
var object_type = (ObjectType) base_type;
if (object_type.type_symbol is Class) {
write_indent ();
stream.printf ("<object name=\"%s\"/>\n", class_type.class_symbol.get_full_name ());
} else if (iface_type != null) {
stream.printf ("<object name=\"%s\"/>\n", object_type.type_symbol.get_full_name ());
} else if (object_type.type_symbol is Interface) {
write_indent ();
stream.printf ("<interface name=\"%s\"/>\n", iface_type.interface_symbol.get_full_name ());
stream.printf ("<interface name=\"%s\"/>\n", object_type.type_symbol.get_full_name ());
} else {
assert_not_reached ();
}
......
......@@ -34,7 +34,6 @@ libvalacore_la_VALASOURCES = \
valacfgbuilder.vala \
valacharacterliteral.vala \
valaclass.vala \
valaclassinstancetype.vala \
valaclasstype.vala \
valacodebinding.vala \
valacodecontext.vala \
......@@ -79,7 +78,6 @@ libvalacore_la_VALASOURCES = \
valaintegerliteral.vala \
valaintegertype.vala \
valainterface.vala \
valainterfaceinstancetype.vala \
valainterfacetype.vala \
valainterfacewriter.vala \
valainvalidtype.vala \
......@@ -102,6 +100,7 @@ libvalacore_la_VALASOURCES = \
valanullliteral.vala \
valanulltype.vala \
valaobjectcreationexpression.vala \
valaobjecttype.vala \
valaobjecttypesymbol.vala \
valaparenthesizedexpression.vala \
valaparser.vala \
......
......@@ -144,7 +144,7 @@ public class Vala.Class : ObjectTypesymbol {
if (_destructor.this_parameter != null) {
_destructor.scope.remove (_destructor.this_parameter.name);
}
_destructor.this_parameter = new FormalParameter ("this", new ClassInstanceType (this));
_destructor.this_parameter = new FormalParameter ("this", new ObjectType (this));
_destructor.scope.add (_destructor.this_parameter.name, _destructor.this_parameter);
}
}
......@@ -251,7 +251,7 @@ public class Vala.Class : ObjectTypesymbol {
if (m.this_parameter != null) {
m.scope.remove (m.this_parameter.name);
}
m.this_parameter = new FormalParameter ("this", new ClassInstanceType (this));
m.this_parameter = new FormalParameter ("this", new ObjectType (this));
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
......@@ -300,7 +300,7 @@ public class Vala.Class : ObjectTypesymbol {
properties.add (prop);
scope.add (prop.name, prop);
prop.this_parameter = new FormalParameter ("this", new ClassInstanceType (this));
prop.this_parameter = new FormalParameter ("this", new ObjectType (this));
prop.scope.add (prop.this_parameter.name, prop.this_parameter);
if (prop.field != null) {
......
......@@ -128,7 +128,7 @@ public class Vala.Interface : ObjectTypesymbol {
return;
}
if (m.binding == MemberBinding.INSTANCE) {
m.this_parameter = new FormalParameter ("this", new InterfaceInstanceType (this));
m.this_parameter = new FormalParameter ("this", new ObjectType (this));
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
......
/* valainterfaceinstancetype.vala
*
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
/**
* An interface type.
*/
public class Vala.InterfaceInstanceType : ReferenceType {
/**
* The referred interface.
*/
public weak Interface interface_symbol { get; set; }
public InterfaceInstanceType (Interface interface_symbol) {
this.interface_symbol = interface_symbol;
data_type = interface_symbol;
}
public override DataType copy () {
var result = new InterfaceInstanceType (interface_symbol);
result.source_reference = source_reference;
result.value_owned = value_owned;
result.nullable = nullable;
result.is_dynamic = is_dynamic;
result.floating_reference = floating_reference;
foreach (DataType arg in get_type_arguments ()) {
result.add_type_argument (arg.copy ());
}
return result;
}
public override string? get_cname () {
return "%s*".printf (interface_symbol.get_cname (!value_owned));
}
}
/* valaclassinstancetype.vala
/* valaobjecttype.vala
*
* Copyright (C) 2007-2008 Jürg Billeter
*
......@@ -25,19 +25,19 @@ using GLib;
/**
* A class type.
*/
public class Vala.ClassInstanceType : ReferenceType {
public class Vala.ObjectType : ReferenceType {
/**
* The referred class.
* The referred class or interface.
*/
public weak Class class_symbol { get; set; }
public weak ObjectTypesymbol type_symbol { get; set; }
public ClassInstanceType (Class class_symbol) {
this.class_symbol = class_symbol;
data_type = class_symbol;
public ObjectType (ObjectTypesymbol type_symbol) {
this.type_symbol = type_symbol;
data_type = type_symbol;
}
public override DataType copy () {
var result = new ClassInstanceType (class_symbol);
var result = new ObjectType (type_symbol);
result.source_reference = source_reference;
result.value_owned = value_owned;
result.nullable = nullable;
......@@ -52,6 +52,6 @@ public class Vala.ClassInstanceType : ReferenceType {
}
public override string? get_cname () {
return "%s*".printf (class_symbol.get_cname (!value_owned));
return "%s*".printf (type_symbol.get_cname (!value_owned));
}
}
......@@ -73,7 +73,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
root_symbol = context.root;
bool_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("bool"));
string_type = new ClassInstanceType ((Class) root_symbol.scope.lookup ("string"));
string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
int_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("int"));
uint_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("uint"));
......@@ -89,15 +89,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
type_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Type"));
glist_type = new ClassInstanceType ((Class) glib_ns.scope.lookup ("List"));
gslist_type = new ClassInstanceType ((Class) glib_ns.scope.lookup ("SList"));
glist_type = new ObjectType ((Class) glib_ns.scope.lookup ("List"));
gslist_type = new ObjectType ((Class) glib_ns.scope.lookup ("SList"));
gerror_type = (Class) glib_ns.scope.lookup ("Error");
}
var gee_ns = root_symbol.scope.lookup ("Gee");
if (gee_ns != null) {
iterable_type = new InterfaceInstanceType ((Interface) gee_ns.scope.lookup ("Iterable"));
iterable_type = new ObjectType ((Interface) gee_ns.scope.lookup ("Iterable"));
iterator_type = (Interface) gee_ns.scope.lookup ("Iterator");
list_type = (Interface) gee_ns.scope.lookup ("List");
map_type = (Interface) gee_ns.scope.lookup ("Map");
......@@ -778,7 +778,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
public override void visit_constructor (Constructor c) {
c.this_parameter = new FormalParameter ("this", new ClassInstanceType (current_class));
c.this_parameter = new FormalParameter ("this", new ObjectType (current_class));
c.scope.add (c.this_parameter.name, c.this_parameter);
c.owner = current_symbol.scope;
......@@ -1150,7 +1150,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
need_type_check = true;
}
} else if (iterable_type != null && collection_type.compatible (iterable_type)) {
var foreach_iterator_type = new InterfaceInstanceType (iterator_type);
var foreach_iterator_type = new ObjectType (iterator_type);
foreach_iterator_type.value_owned = true;
foreach_iterator_type.add_type_argument (stmt.type_reference);
stmt.iterator_variable = new LocalVariable (foreach_iterator_type, "%s_it".printf (stmt.variable_name));
......@@ -2077,9 +2077,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
// construct a new type reference for the base type with correctly linked type arguments
ReferenceType instance_base_type;
if (base_type.data_type is Class) {
instance_base_type = new ClassInstanceType ((Class) base_type.data_type);
instance_base_type = new ObjectType ((Class) base_type.data_type);
} else {
instance_base_type = new InterfaceInstanceType ((Interface) base_type.data_type);
instance_base_type = new ObjectType ((Interface) base_type.data_type);
}
foreach (DataType type_arg in base_type.get_type_arguments ()) {
if (type_arg.type_parameter != null) {
......@@ -2347,7 +2347,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
Report.error (expr.source_reference, "Base access invalid without base class");
return;
} else {
expr.value_type = new ClassInstanceType (current_class.base_class);
expr.value_type = new ObjectType (current_class.base_class);
}
expr.symbol_reference = expr.value_type.data_type;
......@@ -2402,7 +2402,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (type_sym is Class) {
type = (Typesymbol) type_sym;
expr.type_reference = new ClassInstanceType ((Class) type);
expr.type_reference = new ObjectType ((Class) type);
} else if (type_sym is Struct) {
type = (Typesymbol) type_sym;
expr.type_reference = new ValueType (type);
......@@ -2743,8 +2743,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
if (!(expr.inner.value_type is ValueType
|| expr.inner.value_type is ClassInstanceType
|| expr.inner.value_type is InterfaceInstanceType
|| expr.inner.value_type is ObjectType
|| expr.inner.value_type is PointerType)) {
expr.error = true;
Report.error (expr.source_reference, "Address-of operator not supported for this expression");
......
......@@ -98,9 +98,9 @@ public class Vala.Signal : Member, Lockable {
ReferenceType sender_type;
if (parent_symbol is Class) {
sender_type = new ClassInstanceType ((Class) parent_symbol);
sender_type = new ObjectType ((Class) parent_symbol);
} else {
sender_type = new InterfaceInstanceType ((Interface) parent_symbol);
sender_type = new ObjectType ((Interface) parent_symbol);
}
var sender_param = new FormalParameter ("sender", sender_type);
generated_delegate.add_parameter (sender_param);
......
......@@ -256,10 +256,10 @@ public class Vala.SymbolResolver : CodeVisitor {
if (cl.is_error_base) {
type = new ErrorType (null, unresolved_type.source_reference);
} else {
type = new ClassInstanceType (cl);
type = new ObjectType (cl);
}
} else if (sym is Interface) {
type = new InterfaceInstanceType ((Interface) sym);
type = new ObjectType ((Interface) sym);
} else if (sym is Struct) {
type = new ValueType ((Struct) sym);
} else if (sym is Enum) {
......
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