From 5ed95ffb0596aa73061a5ad7590539f09a5e84d0 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Tue, 4 Dec 2007 13:28:30 +0000 Subject: [PATCH] add NullType and VoidType classes 2007-12-04 Juerg Billeter * vala/Makefile.am, vala/valanulltype.vala, vala/valavoidtype.vala, gobject/valaccodegenerator.vala: add NullType and VoidType classes svn path=/trunk/; revision=754 --- ChangeLog | 5 +++ gobject/valaccodegenerator.vala | 71 +++++++++++------------------------------ vala/Makefile.am | 2 ++ vala/valanulltype.vala | 31 ++++++++++++++++++ vala/valavoidtype.vala | 31 ++++++++++++++++++ 5 files changed, 88 insertions(+), 52 deletions(-) create mode 100644 vala/valanulltype.vala create mode 100644 vala/valavoidtype.vala diff --git a/ChangeLog b/ChangeLog index 80dd1dd..f0c0cb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-12-04 Jürg Billeter + * vala/Makefile.am, vala/valanulltype.vala, vala/valavoidtype.vala, + gobject/valaccodegenerator.vala: add NullType and VoidType classes + +2007-12-04 Jürg Billeter + * vala/Makefile.am, vala/valaarraytype.vala, vala/valapointertype.vala, vala/valareferencetype.vala, vala/valavaluetype.vala, gobject/valaccodegenerator.vala, diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 7b42093..ddbcd0f 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -200,47 +200,20 @@ public class Vala.CCodeGenerator : CodeGenerator { root_symbol = context.root; - bool_type = new DataType (); - bool_type.data_type = (Typesymbol) root_symbol.scope.lookup ("bool"); - - char_type = new DataType (); - char_type.data_type = (Typesymbol) root_symbol.scope.lookup ("char"); - - unichar_type = new DataType (); - unichar_type.data_type = (Typesymbol) root_symbol.scope.lookup ("unichar"); - - short_type = new DataType (); - short_type.data_type = (Typesymbol) root_symbol.scope.lookup ("short"); - - ushort_type = new DataType (); - ushort_type.data_type = (Typesymbol) root_symbol.scope.lookup ("ushort"); - - int_type = new DataType (); - int_type.data_type = (Typesymbol) root_symbol.scope.lookup ("int"); - - uint_type = new DataType (); - uint_type.data_type = (Typesymbol) root_symbol.scope.lookup ("uint"); - - long_type = new DataType (); - long_type.data_type = (Typesymbol) root_symbol.scope.lookup ("long"); - - ulong_type = new DataType (); - ulong_type.data_type = (Typesymbol) root_symbol.scope.lookup ("ulong"); - - int64_type = new DataType (); - int64_type.data_type = (Typesymbol) root_symbol.scope.lookup ("int64"); - - uint64_type = new DataType (); - uint64_type.data_type = (Typesymbol) root_symbol.scope.lookup ("uint64"); - - float_type = new DataType (); - float_type.data_type = (Typesymbol) root_symbol.scope.lookup ("float"); - - double_type = new DataType (); - double_type.data_type = (Typesymbol) root_symbol.scope.lookup ("double"); - - string_type = new DataType (); - string_type.data_type = (Typesymbol) root_symbol.scope.lookup ("string"); + bool_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("bool")); + char_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("char")); + unichar_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("unichar")); + short_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("short")); + ushort_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("ushort")); + int_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("int")); + uint_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("uint")); + long_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("long")); + ulong_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("ulong")); + int64_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("int64")); + 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")); substring_method = (Method) string_type.data_type.scope.lookup ("substring"); var glib_ns = root_symbol.scope.lookup ("GLib"); @@ -253,11 +226,8 @@ public class Vala.CCodeGenerator : CodeGenerator { gstring_type = (Typesymbol) glib_ns.scope.lookup ("String"); garray_type = (Typesymbol) glib_ns.scope.lookup ("Array"); - gquark_type = new DataType (); - gquark_type.data_type = (Typesymbol) glib_ns.scope.lookup ("Quark"); - - mutex_type = new DataType (); - mutex_type.data_type = (Typesymbol) glib_ns.scope.lookup ("Mutex"); + gquark_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Quark")); + mutex_type = new ReferenceType ((Class) glib_ns.scope.lookup ("Mutex")); type_module_type = (Typesymbol) glib_ns.scope.lookup ("TypeModule"); @@ -466,8 +436,7 @@ public class Vala.CCodeGenerator : CodeGenerator { var arr = (Array) f.type_reference.data_type; for (int dim = 1; dim <= arr.rank; dim++) { - var len_type = new DataType (); - len_type.data_type = int_type.data_type; + var len_type = int_type.copy (); st.add_field (len_type.get_cname (), get_array_length_cname (f.name, dim)); } @@ -562,8 +531,7 @@ public class Vala.CCodeGenerator : CodeGenerator { if (acc.readable) { current_return_type = prop.type_reference; } else { - // void - current_return_type = new DataType (); + current_return_type = new VoidType (); } acc.accept_children (this); @@ -893,8 +861,7 @@ public class Vala.CCodeGenerator : CodeGenerator { for (int dim = 1; dim <= arr.rank; dim++) { var len_decl = new VariableDeclarator (get_array_length_cname (decl.name, dim)); - len_decl.type_reference = new DataType (); - len_decl.type_reference.data_type = int_type.data_type; + len_decl.type_reference = int_type.copy (); temp_vars.insert (0, len_decl); } diff --git a/vala/Makefile.am b/vala/Makefile.am index 6f5a073..c7023a7 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -81,6 +81,7 @@ libvalacore_la_VALASOURCES = \ valanamespace.vala \ valanamespacereference.vala \ valanullliteral.vala \ + valanulltype.vala \ valaobjectcreationexpression.vala \ valaparenthesizedexpression.vala \ valaparser.vala \ @@ -120,6 +121,7 @@ libvalacore_la_VALASOURCES = \ valaunresolvedtype.vala \ valavaluetype.vala \ valavariabledeclarator.vala \ + valavoidtype.vala \ valawhilestatement.vala \ $(NULL) diff --git a/vala/valanulltype.vala b/vala/valanulltype.vala new file mode 100644 index 0000000..2efbaaa --- /dev/null +++ b/vala/valanulltype.vala @@ -0,0 +1,31 @@ +/* valanulltype.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 + */ + +using GLib; + +/** + * The type of the null literal. + */ +public class Vala.NullType : ReferenceType { + public NullType () { + } +} diff --git a/vala/valavoidtype.vala b/vala/valavoidtype.vala new file mode 100644 index 0000000..bfe30e3 --- /dev/null +++ b/vala/valavoidtype.vala @@ -0,0 +1,31 @@ +/* valavoidtype.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 + */ + +using GLib; + +/** + * The void type. + */ +public class Vala.VoidType : DataType { + public VoidType () { + } +} -- 2.7.4