summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--gobject/valaccodegenerator.vala11
-rw-r--r--gobject/valaccodegeneratormemberaccess.vala2
-rw-r--r--gobject/valaccodegeneratormethod.vala19
-rw-r--r--gobject/valadbusbindingprovider.vala2
-rw-r--r--vala/Makefile.am2
-rw-r--r--vala/valaarraytype.vala2
-rw-r--r--vala/valaclass.vala4
-rw-r--r--vala/valaclasstype.vala37
-rw-r--r--vala/valainterface.vala2
-rw-r--r--vala/valainterfacetype.vala37
-rw-r--r--vala/valareferencetype.vala12
-rw-r--r--vala/valasemanticanalyzer.vala45
-rw-r--r--vala/valasignal.vala2
14 files changed, 144 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index 05ff94661..5527f11d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2007-12-15 Jürg Billeter <j@bitron.ch>
+ * vala/Makefile.am, vala/valaarraytype.vala, vala/valaclass.vala,
+ vala/valaclasstype.vala, vala/valainterface.vala,
+ vala/valainterfacetype.vala, vala/valareferencetype.vala,
+ vala/valasemanticanalyzer.vala, vala/valasignal.vala,
+ gobject/valaccodegenerator.vala,
+ gobject/valaccodegeneratormemberaccess.vala,
+ gobject/valaccodegeneratormethod.vala,
+ gobject/valadbusbindingprovider.vala: add ClassType and InterfaceType
+ classes, let ArrayType derive from ReferenceType, mark ReferenceType
+ as abstract
+
+2007-12-15 Jürg Billeter <j@bitron.ch>
+
* vala/valadatatype.vala, vala/valasemanticanalyzer.vala: refactor
collection type check
diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala
index 4f7a3b9a2..0d61f3fcd 100644
--- a/gobject/valaccodegenerator.vala
+++ b/gobject/valaccodegenerator.vala
@@ -213,7 +213,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 ReferenceType ((Class) root_symbol.scope.lookup ("string"));
+ string_type = new ClassType ((Class) root_symbol.scope.lookup ("string"));
substring_method = (Method) string_type.data_type.scope.lookup ("substring");
var glib_ns = root_symbol.scope.lookup ("GLib");
@@ -227,7 +227,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
garray_type = (Typesymbol) glib_ns.scope.lookup ("Array");
gquark_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Quark"));
- mutex_type = new ReferenceType ((Class) glib_ns.scope.lookup ("Mutex"));
+ mutex_type = new ClassType ((Class) glib_ns.scope.lookup ("Mutex"));
type_module_type = (Typesymbol) glib_ns.scope.lookup ("TypeModule");
@@ -540,7 +540,12 @@ public class Vala.CCodeGenerator : CodeGenerator {
var t = (Typesymbol) prop.parent_symbol;
- var this_type = new ReferenceType (t);
+ ReferenceType this_type;
+ if (t is Class) {
+ this_type = new ClassType ((Class) t);
+ } else {
+ this_type = new InterfaceType ((Interface) t);
+ }
var cselfparam = new CCodeFormalParameter ("self", this_type.get_cname ());
var cvalueparam = new CCodeFormalParameter ("value", prop.type_reference.get_cname (false, true));
diff --git a/gobject/valaccodegeneratormemberaccess.vala b/gobject/valaccodegeneratormemberaccess.vala
index d93d5575f..e0b0e635e 100644
--- a/gobject/valaccodegeneratormemberaccess.vala
+++ b/gobject/valaccodegeneratormemberaccess.vala
@@ -200,7 +200,7 @@ public class Vala.CCodeGenerator {
if (current_type_symbol != null) {
/* base type is available if this is a type method */
if (current_type_symbol is Class) {
- base_type = new ReferenceType ((Class) current_type_symbol);
+ base_type = new ClassType ((Class) current_type_symbol);
} else {
base_type = new ValueType (current_type_symbol);
pub_inst = new CCodeIdentifier ("(*self)");
diff --git a/gobject/valaccodegeneratormethod.vala b/gobject/valaccodegeneratormethod.vala
index c69db54b4..6d643ad69 100644
--- a/gobject/valaccodegeneratormethod.vala
+++ b/gobject/valaccodegeneratormethod.vala
@@ -55,7 +55,7 @@ public class Vala.CCodeGenerator {
}
if (cl != null) {
- creturn_type = new ReferenceType (cl);
+ creturn_type = new ClassType (cl);
}
}
@@ -127,10 +127,10 @@ public class Vala.CCodeGenerator {
var this_type = new DataType ();
this_type.data_type = find_parent_type (m);
if (m.base_interface_method != null && !m.is_abstract && !m.is_virtual) {
- var base_type = new ReferenceType ((Typesymbol) m.base_interface_method.parent_symbol);
+ var base_type = new InterfaceType ((Interface) m.base_interface_method.parent_symbol);
instance_param = new CCodeFormalParameter ("base", base_type.get_cname ());
} else if (m.overrides) {
- var base_type = new ReferenceType ((Typesymbol) m.base_method.parent_symbol);
+ var base_type = new ClassType ((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 ()) {
@@ -245,13 +245,15 @@ public class Vala.CCodeGenerator {
var cl = (Class) m.parent_symbol;
if (m.overrides || (m.base_interface_method != null && !m.is_abstract && !m.is_virtual)) {
Method base_method;
+ ReferenceType base_expression_type;
if (m.overrides) {
base_method = m.base_method;
+ base_expression_type = new ClassType ((Class) base_method.parent_symbol);
} else {
base_method = m.base_interface_method;
+ base_expression_type = new InterfaceType ((Interface) base_method.parent_symbol);
}
- var base_expression_type = new ReferenceType ((Typesymbol) base_method.parent_symbol);
- var self_target_type = new ReferenceType (cl);
+ var self_target_type = new ClassType (cl);
CCodeExpression cself = get_implicit_cast_expression (new CCodeIdentifier ("base"), base_expression_type, self_target_type);
var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
@@ -382,7 +384,12 @@ public class Vala.CCodeGenerator {
var vfunc = new CCodeFunction (m.get_cname (), creturn_type.get_cname ());
vfunc.line = function.line;
- var this_type = new ReferenceType ((Typesymbol) m.parent_symbol);
+ ReferenceType this_type;
+ if (m.parent_symbol is Class) {
+ this_type = new ClassType ((Class) m.parent_symbol);
+ } else {
+ this_type = new InterfaceType ((Interface) m.parent_symbol);
+ }
var cparam = new CCodeFormalParameter ("self", this_type.get_cname ());
vfunc.add_parameter (cparam);
diff --git a/gobject/valadbusbindingprovider.vala b/gobject/valadbusbindingprovider.vala
index 6abdfde5f..7e8b40299 100644
--- a/gobject/valadbusbindingprovider.vala
+++ b/gobject/valadbusbindingprovider.vala
@@ -67,7 +67,7 @@ public class Vala.DBusBindingProvider : Object, BindingProvider {
m.set_cname ("dbus_g_proxy_new_for_name");
m.add_cheader_filename ("dbus/dbus-glib.h");
m.access = SymbolAccessibility.PUBLIC;
- var string_type_ref = new ReferenceType (string_type);
+ var string_type_ref = new ClassType (string_type);
m.add_parameter (_context.create_formal_parameter ("name", string_type_ref));
m.add_parameter (_context.create_formal_parameter ("path", string_type_ref));
symbols.add (m);
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 20ba18f28..8e7890468 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -34,6 +34,7 @@ libvalacore_la_VALASOURCES = \
valacatchclause.vala \
valacharacterliteral.vala \
valaclass.vala \
+ valaclasstype.vala \
valacodebinding.vala \
valacodecontext.vala \
valacodegenerator.vala \
@@ -64,6 +65,7 @@ libvalacore_la_VALASOURCES = \
valainstancecast.vala \
valaintegerliteral.vala \
valainterface.vala \
+ valainterfacetype.vala \
valainterfacewriter.vala \
valainvocationexpression.vala \
valalambdaexpression.vala \
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index ef85b299d..cf3463ad0 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -25,7 +25,7 @@ using GLib;
/**
* An array type.
*/
-public class Vala.ArrayType : DataType {
+public class Vala.ArrayType : ReferenceType {
/**
* The element type.
*/
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index ef9c0668f..00f3fe08c 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -189,7 +189,7 @@ public class Vala.Class : Typesymbol {
*/
public void add_method (Method! m) {
if (m.instance || m is CreationMethod) {
- m.this_parameter = new FormalParameter ("this", new ReferenceType (this));
+ m.this_parameter = new FormalParameter ("this", new ClassType (this));
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (m is CreationMethod) {
@@ -223,7 +223,7 @@ public class Vala.Class : Typesymbol {
properties.add (prop);
scope.add (prop.name, prop);
- prop.this_parameter = new FormalParameter ("this", new ReferenceType (this));
+ prop.this_parameter = new FormalParameter ("this", new ClassType (this));
prop.scope.add (prop.this_parameter.name, prop.this_parameter);
if (!no_field && prop.set_accessor != null && prop.set_accessor.body == null &&
diff --git a/vala/valaclasstype.vala b/vala/valaclasstype.vala
new file mode 100644
index 000000000..e9d64fba4
--- /dev/null
+++ b/vala/valaclasstype.vala
@@ -0,0 +1,37 @@
+/* valaclasstype.vala
+ *
+ * Copyright (C) 2007 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;
+
+/**
+ * A class type.
+ */
+public class Vala.ClassType : ReferenceType {
+ /**
+ * The referred class.
+ */
+ public weak Class class_symbol { get; set; }
+
+ public ClassType (construct Class! class_symbol) {
+ data_type = class_symbol;
+ }
+}
diff --git a/vala/valainterface.vala b/vala/valainterface.vala
index 4b717bf42..c1da55423 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -122,7 +122,7 @@ public class Vala.Interface : Typesymbol {
return;
}
if (m.instance) {
- m.this_parameter = new FormalParameter ("this", new ReferenceType (this));
+ m.this_parameter = new FormalParameter ("this", new InterfaceType (this));
m.scope.add (m.this_parameter.name, m.this_parameter);
}
diff --git a/vala/valainterfacetype.vala b/vala/valainterfacetype.vala
new file mode 100644
index 000000000..9e515804a
--- /dev/null
+++ b/vala/valainterfacetype.vala
@@ -0,0 +1,37 @@
+/* valainterfacetype.vala
+ *
+ * Copyright (C) 2007 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.InterfaceType : ReferenceType {
+ /**
+ * The referred interface.
+ */
+ public weak Interface interface_symbol { get; set; }
+
+ public InterfaceType (construct Interface! interface_symbol) {
+ data_type = interface_symbol;
+ }
+}
diff --git a/vala/valareferencetype.vala b/vala/valareferencetype.vala
index 08b609723..6b49f53cc 100644
--- a/vala/valareferencetype.vala
+++ b/vala/valareferencetype.vala
@@ -23,15 +23,7 @@
using GLib;
/**
- * A reference type, i.e. a class or interface type.
+ * A reference type, i.e. a class, interface, or array type.
*/
-public class Vala.ReferenceType : DataType {
- /**
- * The referred class or interface.
- */
- public weak Typesymbol type_symbol { get; set; }
-
- public ReferenceType (construct Typesymbol! type_symbol) {
- data_type = type_symbol;
- }
+public abstract class Vala.ReferenceType : DataType {
}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index fe4e7b9ad..9f8bb55e0 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -52,15 +52,15 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
DataType unichar_type;
DataType type_type;
Typesymbol pointer_type;
- Typesymbol object_type;
+ Class object_type;
Typesymbol initially_unowned_type;
DataType glist_type;
DataType gslist_type;
- Typesymbol gerror_type;
+ Class gerror_type;
DataType iterable_type;
- Typesymbol iterator_type;
- Typesymbol list_type;
- Typesymbol map_type;
+ Interface iterator_type;
+ Interface list_type;
+ Interface map_type;
private int next_lambda_id = 0;
@@ -85,7 +85,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
root_symbol = context.root;
bool_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("bool"));
- string_type = new ReferenceType ((Typesymbol) root_symbol.scope.lookup ("string"));
+ string_type = new ClassType ((Class) root_symbol.scope.lookup ("string"));
pointer_type = (Typesymbol) root_symbol.scope.lookup ("pointer");
@@ -97,23 +97,23 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
// TODO: don't require GLib namespace in semantic analyzer
var glib_ns = root_symbol.scope.lookup ("GLib");
if (glib_ns != null) {
- object_type = (Typesymbol) glib_ns.scope.lookup ("Object");
+ object_type = (Class) glib_ns.scope.lookup ("Object");
initially_unowned_type = (Typesymbol) glib_ns.scope.lookup ("InitiallyUnowned");
type_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Type"));
- glist_type = new ReferenceType ((Typesymbol) glib_ns.scope.lookup ("List"));
- gslist_type = new ReferenceType ((Typesymbol) glib_ns.scope.lookup ("SList"));
+ glist_type = new ClassType ((Class) glib_ns.scope.lookup ("List"));
+ gslist_type = new ClassType ((Class) glib_ns.scope.lookup ("SList"));
- gerror_type = (Typesymbol) glib_ns.scope.lookup ("Error");
+ gerror_type = (Class) glib_ns.scope.lookup ("Error");
}
var gee_ns = root_symbol.scope.lookup ("Gee");
if (gee_ns != null) {
- 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");
+ iterable_type = new InterfaceType ((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");
}
current_symbol = root_symbol;
@@ -615,7 +615,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
public override void visit_constructor (Constructor! c) {
- c.this_parameter = new FormalParameter ("this", new ReferenceType (current_class));
+ c.this_parameter = new FormalParameter ("this", new ClassType (current_class));
c.scope.add (c.this_parameter.name, c.this_parameter);
c.owner = current_symbol.scope;
@@ -912,7 +912,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 = new InterfaceType (iterator_type);
stmt.iterator_variable_declarator.type_reference.takes_ownership = true;
stmt.iterator_variable_declarator.type_reference.add_type_argument (stmt.type_reference);
@@ -989,7 +989,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
current_source_file.add_type_dependency (clause.type_reference, SourceFileDependencyType.SOURCE);
clause.variable_declarator = new VariableDeclarator (clause.variable_name);
- clause.variable_declarator.type_reference = new ReferenceType (gerror_type);
+ clause.variable_declarator.type_reference = new ClassType (gerror_type);
clause.body.scope.add (clause.variable_name, clause.variable_declarator);
@@ -1614,7 +1614,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
foreach (DataType base_type in base_types) {
if (SemanticAnalyzer.symbol_lookup_inherited (base_type.data_type, generic_member.name) != null) {
// construct a new type reference for the base type with correctly linked type arguments
- var instance_base_type = new ReferenceType (base_type.data_type);
+ ReferenceType instance_base_type;
+ if (base_type.data_type is Class) {
+ instance_base_type = new ClassType ((Class) base_type.data_type);
+ } else {
+ instance_base_type = new InterfaceType ((Interface) base_type.data_type);
+ }
foreach (DataType type_arg in base_type.get_type_arguments ()) {
if (type_arg.type_parameter != null) {
// link to type argument of derived type
@@ -1764,7 +1769,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
base_type_it.next ();
expr.static_type = base_type_it.get ();
} else {
- expr.static_type = new ReferenceType (current_class.base_class);
+ expr.static_type = new ClassType (current_class.base_class);
}
expr.symbol_reference = expr.static_type.data_type;
@@ -1817,7 +1822,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (type_sym is Class) {
type = (Typesymbol) type_sym;
- expr.type_reference = new ReferenceType (type);
+ expr.type_reference = new ClassType ((Class) type);
} else if (type_sym is Struct) {
type = (Typesymbol) type_sym;
expr.type_reference = new ValueType (type);
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index b0820c082..d9db2ff79 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -87,7 +87,7 @@ public class Vala.Signal : Member, Lockable {
generated_callback = new Callback (null, return_type);
generated_callback.instance = true;
- var sender_type = new ReferenceType ((Typesymbol) parent_symbol);
+ var sender_type = new ClassType ((Class) parent_symbol);
var sender_param = new FormalParameter ("sender", sender_type);
generated_callback.add_parameter (sender_param);