From: Jürg Billeter Date: Sat, 3 Jan 2009 14:02:48 +0000 (+0000) Subject: Add BooleanType, EnumValueType, FloatingType, and StructValueType as X-Git-Tag: VALA_0_5_4~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d19da45e60ffec828f352572249cfbc46d9cbb08;p=thirdparty%2Fvala.git Add BooleanType, EnumValueType, FloatingType, and StructValueType as 2009-01-03 Jürg Billeter * vala/Makefile.am: * vala/valaarraytype.vala: * vala/valabinaryexpression.vala: * vala/valabooleantype.vala: * vala/valacharacterliteral.vala: * vala/valadostatement.vala: * vala/valaenum.vala: * vala/valaenumvaluetype.vala: * vala/valaerrordomain.vala: * vala/valafloatingtype.vala: * vala/valaintegerliteral.vala: * vala/valaintegertype.vala: * vala/valaobjectcreationexpression.vala: * vala/valarealliteral.vala: * vala/valasemanticanalyzer.vala: * vala/valastruct.vala: * vala/valastructvaluetype.vala: * vala/valasymbolresolver.vala: * vala/valavaluetype.vala: * gobject/valaccodebasemodule.vala: * gobject/valaccodemethodmodule.vala: * vapi/glib-2.0.vapi: Add BooleanType, EnumValueType, FloatingType, and StructValueType as ValueType subclasses svn path=/trunk/; revision=2256 --- diff --git a/ChangeLog b/ChangeLog index b6fe9af50..f8bbf9916 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2009-01-03 Jürg Billeter + + * vala/Makefile.am: + * vala/valaarraytype.vala: + * vala/valabinaryexpression.vala: + * vala/valabooleantype.vala: + * vala/valacharacterliteral.vala: + * vala/valadostatement.vala: + * vala/valaenum.vala: + * vala/valaenumvaluetype.vala: + * vala/valaerrordomain.vala: + * vala/valafloatingtype.vala: + * vala/valaintegerliteral.vala: + * vala/valaintegertype.vala: + * vala/valaobjectcreationexpression.vala: + * vala/valarealliteral.vala: + * vala/valasemanticanalyzer.vala: + * vala/valastruct.vala: + * vala/valastructvaluetype.vala: + * vala/valasymbolresolver.vala: + * vala/valavaluetype.vala: + * gobject/valaccodebasemodule.vala: + * gobject/valaccodemethodmodule.vala: + * vapi/glib-2.0.vapi: + + Add BooleanType, EnumValueType, FloatingType, and StructValueType + as ValueType subclasses + 2009-01-02 Jürg Billeter * vapi/packages/gdk-2.0/gdk-2.0.metadata: diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index c3378f7a3..25d169374 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -1,6 +1,6 @@ /* valaccodebasemodule.vala * - * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini + * Copyright (C) 2006-2009 Jürg Billeter, Raffaele Sandrini * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -553,26 +553,26 @@ public class Vala.CCodeBaseModule : CCodeModule { root_symbol = context.root; - bool_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("bool")); - char_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("char")); - uchar_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uchar")); - 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")); - int8_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int8")); - uint8_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uint8")); - int16_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int16")); - uint16_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uint16")); - int32_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int32")); - uint32_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uint32")); - 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")); + bool_type = new BooleanType ((Struct) root_symbol.scope.lookup ("bool")); + char_type = new IntegerType ((Struct) root_symbol.scope.lookup ("char")); + uchar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uchar")); + unichar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("unichar")); + short_type = new IntegerType ((Struct) root_symbol.scope.lookup ("short")); + ushort_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ushort")); + int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); + uint_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint")); + long_type = new IntegerType ((Struct) root_symbol.scope.lookup ("long")); + ulong_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ulong")); + int8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int8")); + uint8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint8")); + int16_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int16")); + uint16_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint16")); + int32_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int32")); + uint32_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint32")); + int64_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int64")); + uint64_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint64")); + float_type = new FloatingType ((Struct) root_symbol.scope.lookup ("float")); + double_type = new FloatingType ((Struct) root_symbol.scope.lookup ("double")); string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string")); var glib_ns = root_symbol.scope.lookup ("GLib"); @@ -586,7 +586,7 @@ public class Vala.CCodeBaseModule : CCodeModule { garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array"); gbytearray_type = (TypeSymbol) glib_ns.scope.lookup ("ByteArray"); - gquark_type = new ValueType ((TypeSymbol) glib_ns.scope.lookup ("Quark")); + gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark")); gvalue_type = (Struct) glib_ns.scope.lookup ("Value"); mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex"); @@ -3496,9 +3496,18 @@ public class Vala.CCodeBaseModule : CCodeModule { } else if (sym is Interface) { type = new ObjectType ((Interface) sym); } else if (sym is Struct) { - type = new ValueType ((Struct) sym); + var st = (Struct) sym; + if (st.is_boolean_type ()) { + type = new BooleanType (st); + } else if (st.is_integer_type ()) { + type = new IntegerType (st); + } else if (st.is_floating_type ()) { + type = new FloatingType (st); + } else { + type = new StructValueType (st); + } } else if (sym is Enum) { - type = new ValueType ((Enum) sym); + type = new EnumValueType ((Enum) sym); } else if (sym is ErrorDomain) { type = new ErrorType ((ErrorDomain) sym, null); } else if (sym is ErrorCode) { diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala index fc7b082c5..b66bb2d34 100644 --- a/gobject/valaccodemethodmodule.vala +++ b/gobject/valaccodemethodmodule.vala @@ -1,6 +1,6 @@ /* valaccodemethodmodule.vala * - * Copyright (C) 2007-2008 Jürg Billeter + * Copyright (C) 2007-2009 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 @@ -346,7 +346,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule { prop_name = new CCodeConstant ("\"%s-type\"".printf (type_param.name.down ())); param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.down ())); - cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new ValueType (gtype_type), param_name))); + cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new IntegerType ((Struct) gtype_type), param_name))); prop_name = new CCodeConstant ("\"%s-dup-func\"".printf (type_param.name.down ())); param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ())); @@ -522,8 +522,12 @@ public class Vala.CCodeMethodModule : CCodeStructModule { this_type = new ObjectType ((Class) parent_type); } else if (parent_type is Interface) { this_type = new ObjectType ((Interface) parent_type); + } else if (parent_type is Struct) { + this_type = new StructValueType ((Struct) parent_type); + } else if (parent_type is Enum) { + this_type = new EnumValueType ((Enum) parent_type); } else { - this_type = new ValueType (parent_type); + assert_not_reached (); } CCodeFormalParameter instance_param = null; diff --git a/vala/Makefile.am b/vala/Makefile.am index 736379650..4579a372d 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -27,6 +27,7 @@ libvalacore_la_VALASOURCES = \ valabinaryexpression.vala \ valablock.vala \ valabooleanliteral.vala \ + valabooleantype.vala \ valabreakstatement.vala \ valacastexpression.vala \ valacatchclause.vala \ @@ -57,6 +58,7 @@ libvalacore_la_VALASOURCES = \ valaemptystatement.vala \ valaenum.vala \ valaenumvalue.vala \ + valaenumvaluetype.vala \ valaerrorcode.vala \ valaerrordomain.vala \ valaerrortype.vala \ @@ -64,6 +66,7 @@ libvalacore_la_VALASOURCES = \ valaexpressionstatement.vala \ valafield.vala \ valafieldprototype.vala \ + valafloatingtype.vala \ valaflowanalyzer.vala \ valaforeachstatement.vala \ valaformalparameter.vala \ @@ -125,6 +128,7 @@ libvalacore_la_VALASOURCES = \ valastatementlist.vala \ valastringliteral.vala \ valastruct.vala \ + valastructvaluetype.vala \ valaswitchlabel.vala \ valaswitchsection.vala \ valaswitchstatement.vala \ diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala index 946c28274..7345e4663 100644 --- a/vala/valaarraytype.vala +++ b/vala/valaarraytype.vala @@ -1,6 +1,6 @@ /* valaarraytype.vala * - * Copyright (C) 2007-2008 Jürg Billeter + * Copyright (C) 2007-2009 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 @@ -74,10 +74,10 @@ public class Vala.ArrayType : ReferenceType { var root_symbol = source_reference.file.context.root; if (rank > 1) { // length is an int[] containing the dimensions of the array, starting at 0 - ValueType integer = new ValueType((TypeSymbol) root_symbol.scope.lookup("int")); + ValueType integer = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); length_field.field_type = new ArrayType (integer, 1, source_reference); } else { - length_field.field_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int")); + length_field.field_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); } } @@ -94,7 +94,7 @@ public class Vala.ArrayType : ReferenceType { resize_method.set_cname ("g_renew"); var root_symbol = source_reference.file.context.root; - var int_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int")); + var int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); resize_method.add_parameter (new FormalParameter ("length", int_type)); @@ -113,7 +113,7 @@ public class Vala.ArrayType : ReferenceType { move_method.set_cname ("_vala_array_move"); var root_symbol = source_reference.file.context.root; - var int_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int")); + var int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); move_method.add_parameter (new FormalParameter ("src", int_type)); move_method.add_parameter (new FormalParameter ("dest", int_type)); diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index f7d4dd653..66ecabe4b 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -1,6 +1,6 @@ /* valabinaryexpression.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -157,7 +157,7 @@ public class Vala.BinaryExpression : Expression { // convert conditional expression into if statement // required for flow analysis and exception handling - var local = new LocalVariable (new ValueType (analyzer.bool_type.data_type), get_temp_name (), null, source_reference); + var local = new LocalVariable (analyzer.bool_type.copy (), get_temp_name (), null, source_reference); var decl = new DeclarationStatement (local, source_reference); decl.check (analyzer); diff --git a/vala/valabooleantype.vala b/vala/valabooleantype.vala new file mode 100644 index 000000000..b224a9359 --- /dev/null +++ b/vala/valabooleantype.vala @@ -0,0 +1,40 @@ +/* valabooleantype.vala + * + * Copyright (C) 2009 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; + +/** + * A boolean type. + */ +public class Vala.BooleanType : ValueType { + public BooleanType (Struct type_symbol) { + base (type_symbol); + } + + public override DataType copy () { + var result = new BooleanType ((Struct) type_symbol); + result.source_reference = source_reference; + result.value_owned = value_owned; + result.nullable = nullable; + return result; + } +} diff --git a/vala/valacharacterliteral.vala b/vala/valacharacterliteral.vala index 019439fe7..1d33c92ef 100644 --- a/vala/valacharacterliteral.vala +++ b/vala/valacharacterliteral.vala @@ -1,6 +1,6 @@ /* valacharacterliteral.vala * - * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini + * Copyright (C) 2006-2009 Jürg Billeter, Raffaele Sandrini * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -85,7 +85,7 @@ public class Vala.CharacterLiteral : Literal { checked = true; - value_type = new ValueType ((TypeSymbol) analyzer.root_symbol.scope.lookup ("char")); + value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup ("char")); return !error; } diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala index c994cb148..efc2d7acd 100644 --- a/vala/valadostatement.vala +++ b/vala/valadostatement.vala @@ -1,6 +1,6 @@ /* valadostatement.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -130,7 +130,7 @@ public class Vala.DoStatement : CodeNode, Statement { * } while (true); */ - var first_local = new LocalVariable (new ValueType (analyzer.bool_type.data_type), get_temp_name (), new BooleanLiteral (false, source_reference), source_reference); + var first_local = new LocalVariable (analyzer.bool_type.copy (), get_temp_name (), new BooleanLiteral (false, source_reference), source_reference); var first_decl = new DeclarationStatement (first_local, source_reference); first_decl.check (analyzer); var block = (Block) analyzer.current_symbol; diff --git a/vala/valaenum.vala b/vala/valaenum.vala index 56eca2b2f..4f2a73ee5 100644 --- a/vala/valaenum.vala +++ b/vala/valaenum.vala @@ -1,6 +1,6 @@ /* valaenum.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -79,7 +79,7 @@ public class Vala.Enum : TypeSymbol { return; } if (m.binding == MemberBinding.INSTANCE) { - m.this_parameter = new FormalParameter ("this", new ValueType (this)); + m.this_parameter = new FormalParameter ("this", new EnumValueType (this)); m.scope.add (m.this_parameter.name, m.this_parameter); } diff --git a/vala/valaenumvaluetype.vala b/vala/valaenumvaluetype.vala new file mode 100644 index 000000000..bf138b00f --- /dev/null +++ b/vala/valaenumvaluetype.vala @@ -0,0 +1,41 @@ +/* valaenumvaluetype.vala + * + * Copyright (C) 2009 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; + +/** + * An enum value type. + */ +public class Vala.EnumValueType : ValueType { + public EnumValueType (Enum type_symbol) { + base (type_symbol); + } + + public override DataType copy () { + var result = new EnumValueType ((Enum) type_symbol); + result.source_reference = source_reference; + result.value_owned = value_owned; + result.nullable = nullable; + + return result; + } +} diff --git a/vala/valaerrordomain.vala b/vala/valaerrordomain.vala index 92ec0b39b..713e452ed 100644 --- a/vala/valaerrordomain.vala +++ b/vala/valaerrordomain.vala @@ -1,6 +1,6 @@ /* valaerrordomain.vala * - * Copyright (C) 2008 Jürg Billeter + * Copyright (C) 2008-2009 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 @@ -68,7 +68,7 @@ public class Vala.ErrorDomain : TypeSymbol { return; } if (m.binding == MemberBinding.INSTANCE) { - m.this_parameter = new FormalParameter ("this", new ValueType (this)); + m.this_parameter = new FormalParameter ("this", new ErrorType (this, null)); m.scope.add (m.this_parameter.name, m.this_parameter); } diff --git a/vala/valafloatingtype.vala b/vala/valafloatingtype.vala new file mode 100644 index 000000000..83c4abee6 --- /dev/null +++ b/vala/valafloatingtype.vala @@ -0,0 +1,40 @@ +/* valafloatingtype.vala + * + * Copyright (C) 2009 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; + +/** + * A floating-point type. + */ +public class Vala.FloatingType : ValueType { + public FloatingType (Struct type_symbol) { + base (type_symbol); + } + + public override DataType copy () { + var result = new FloatingType ((Struct) type_symbol); + result.source_reference = source_reference; + result.value_owned = value_owned; + result.nullable = nullable; + return result; + } +} diff --git a/vala/valaintegerliteral.vala b/vala/valaintegerliteral.vala index 73a2910de..95fd13283 100644 --- a/vala/valaintegerliteral.vala +++ b/vala/valaintegerliteral.vala @@ -114,7 +114,7 @@ public class Vala.IntegerLiteral : Literal { checked = true; - value_type = new IntegerType ((TypeSymbol) analyzer.root_symbol.scope.lookup (get_type_name ()), value, get_type_name ()); + value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup (get_type_name ()), value, get_type_name ()); return !error; } diff --git a/vala/valaintegertype.vala b/vala/valaintegertype.vala index 88eee0390..2c04491b0 100644 --- a/vala/valaintegertype.vala +++ b/vala/valaintegertype.vala @@ -1,6 +1,6 @@ /* valaintegertype.vala * - * Copyright (C) 2008 Jürg Billeter + * Copyright (C) 2008-2009 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 @@ -26,18 +26,21 @@ using GLib; * An integer type. */ public class Vala.IntegerType : ValueType { - string literal_value; - string literal_type_name; + string? literal_value; + string? literal_type_name; - public IntegerType (TypeSymbol type_symbol, string literal_value, string literal_type_name) { - this.type_symbol = type_symbol; - data_type = type_symbol; + public IntegerType (Struct type_symbol, string? literal_value = null, string? literal_type_name = null) { + base (type_symbol); this.literal_value = literal_value; this.literal_type_name = literal_type_name; } public override DataType copy () { - return new IntegerType (type_symbol, literal_value, literal_type_name); + var result = new IntegerType ((Struct) type_symbol, literal_value, literal_type_name); + result.source_reference = source_reference; + result.value_owned = value_owned; + result.nullable = nullable; + return result; } public override bool compatible (DataType target_type) { diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 9fc43fd10..c86539fba 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -1,6 +1,6 @@ /* valaobjectcreationexpression.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -204,7 +204,7 @@ public class Vala.ObjectCreationExpression : Expression { type_reference = new ObjectType ((Class) type); } else if (type_sym is Struct) { type = (TypeSymbol) type_sym; - type_reference = new ValueType (type); + type_reference = new StructValueType ((Struct) type); } else if (type_sym is ErrorCode) { type_reference = new ErrorType ((ErrorDomain) type_sym.parent_symbol, (ErrorCode) type_sym, source_reference); symbol_reference = type_sym; diff --git a/vala/valarealliteral.vala b/vala/valarealliteral.vala index 19d598da8..cbfca7c05 100644 --- a/vala/valarealliteral.vala +++ b/vala/valarealliteral.vala @@ -1,6 +1,6 @@ /* valarealliteral.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -77,7 +77,7 @@ public class Vala.RealLiteral : Literal { checked = true; - value_type = new ValueType ((TypeSymbol) analyzer.root_symbol.scope.lookup (get_type_name ())); + value_type = new FloatingType ((Struct) analyzer.root_symbol.scope.lookup (get_type_name ())); return !error; } diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 9e6e4e7f7..f6e8588e7 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -1,6 +1,6 @@ /* valasemanticanalyzer.vala * - * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini + * Copyright (C) 2006-2009 Jürg Billeter, Raffaele Sandrini * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -83,22 +83,22 @@ public class Vala.SemanticAnalyzer : CodeVisitor { root_symbol = context.root; - bool_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("bool")); + bool_type = new BooleanType ((Struct) root_symbol.scope.lookup ("bool")); string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string")); - uchar_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uchar")); - 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")); - size_t_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("size_t")); - ssize_t_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("ssize_t")); - uint64_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("uint64")); - int8_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("int8")); - unichar_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("unichar")); - double_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("double")); + uchar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uchar")); + short_type = new IntegerType ((Struct) root_symbol.scope.lookup ("short")); + ushort_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ushort")); + int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int")); + uint_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint")); + long_type = new IntegerType ((Struct) root_symbol.scope.lookup ("long")); + ulong_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ulong")); + size_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("size_t")); + ssize_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ssize_t")); + uint64_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint64")); + int8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int8")); + unichar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("unichar")); + double_type = new FloatingType ((Struct) root_symbol.scope.lookup ("double")); // TODO: don't require GLib namespace in semantic analyzer var glib_ns = root_symbol.scope.lookup ("GLib"); @@ -106,7 +106,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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")); + type_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Type")); glist_type = new ObjectType ((Class) glib_ns.scope.lookup ("List")); gslist_type = new ObjectType ((Class) glib_ns.scope.lookup ("SList")); @@ -181,7 +181,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } return type; } else if (sym is EnumValue) { - return new ValueType ((TypeSymbol) sym.parent_symbol); + return new EnumValueType ((Enum) sym.parent_symbol); } else if (sym is Method) { return new MethodType ((Method) sym); } else if (sym is Signal) { @@ -251,9 +251,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor { if (sym is ObjectTypeSymbol) { type = new ObjectType ((ObjectTypeSymbol) sym); } else if (sym is Struct) { - type = new ValueType ((Struct) sym); + var st = (Struct) sym; + if (st.is_boolean_type ()) { + type = new BooleanType (st); + } else if (st.is_integer_type ()) { + type = new IntegerType (st); + } else if (st.is_floating_type ()) { + type = new FloatingType (st); + } else { + type = new StructValueType (st); + } } else if (sym is Enum) { - type = new ValueType ((Enum) sym); + type = new EnumValueType ((Enum) sym); } else if (sym is ErrorDomain) { type = new ErrorType ((ErrorDomain) sym, null); } else if (sym is ErrorCode) { diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 6595f0cc7..5c07de00e 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -1,6 +1,6 @@ /* valastruct.vala * - * Copyright (C) 2006-2008 Jürg Billeter + * Copyright (C) 2006-2009 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 @@ -39,6 +39,7 @@ public class Vala.Struct : TypeSymbol { private string type_id; private string lower_case_cprefix; private string lower_case_csuffix; + private bool boolean_type; private bool integer_type; private bool floating_type; private int rank; @@ -138,7 +139,7 @@ public class Vala.Struct : TypeSymbol { return_if_fail (m != null); if (m.binding == MemberBinding.INSTANCE || m is CreationMethod) { - m.this_parameter = new FormalParameter ("this", new ValueType (this)); + m.this_parameter = new FormalParameter ("this", new StructValueType (this)); m.scope.add (m.this_parameter.name, m.this_parameter); } if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) { @@ -269,6 +270,21 @@ public class Vala.Struct : TypeSymbol { return type_signature; } + /** + * Returns whether this is a boolean type. + * + * @return true if this is a boolean type, false otherwise + */ + public bool is_boolean_type () { + foreach (DataType type in base_types) { + var st = type.data_type as Struct; + if (st != null && st.is_boolean_type ()) { + return true; + } + } + return boolean_type; + } + /** * Returns whether this is an integer type. * @@ -350,13 +366,17 @@ public class Vala.Struct : TypeSymbol { } } + private void process_boolean_type_attribute (Attribute a) { + boolean_type = true; + } + private void process_integer_type_attribute (Attribute a) { integer_type = true; if (a.has_argument ("rank")) { rank = a.get_integer ("rank"); } } - + private void process_floating_type_attribute (Attribute a) { floating_type = true; if (a.has_argument ("rank")) { @@ -371,6 +391,8 @@ public class Vala.Struct : TypeSymbol { foreach (Attribute a in attributes) { if (a.name == "CCode") { process_ccode_attribute (a); + } else if (a.name == "BooleanType") { + process_boolean_type_attribute (a); } else if (a.name == "IntegerType") { process_integer_type_attribute (a); } else if (a.name == "FloatingType") { diff --git a/vala/valastructvaluetype.vala b/vala/valastructvaluetype.vala new file mode 100644 index 000000000..dce8fca1c --- /dev/null +++ b/vala/valastructvaluetype.vala @@ -0,0 +1,45 @@ +/* valastructvaluetype.vala + * + * Copyright (C) 2009 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; + +/** + * A struct value type. + */ +public class Vala.StructValueType : ValueType { + public StructValueType (Struct type_symbol) { + base (type_symbol); + } + + public override DataType copy () { + var result = new StructValueType ((Struct) type_symbol); + result.source_reference = source_reference; + result.value_owned = value_owned; + result.nullable = nullable; + + foreach (DataType arg in get_type_arguments ()) { + result.add_type_argument (arg.copy ()); + } + + return result; + } +} diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 7ce0055e4..be43079f2 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -1,6 +1,6 @@ /* valasymbolresolver.vala * - * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini + * Copyright (C) 2006-2009 Jürg Billeter, Raffaele Sandrini * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -276,9 +276,18 @@ public class Vala.SymbolResolver : CodeVisitor { } else if (sym is Interface) { type = new ObjectType ((Interface) sym); } else if (sym is Struct) { - type = new ValueType ((Struct) sym); + var st = (Struct) sym; + if (st.is_boolean_type ()) { + type = new BooleanType (st); + } else if (st.is_integer_type ()) { + type = new IntegerType (st); + } else if (st.is_floating_type ()) { + type = new FloatingType (st); + } else { + type = new StructValueType (st); + } } else if (sym is Enum) { - type = new ValueType ((Enum) sym); + type = new EnumValueType ((Enum) sym); } else if (sym is ErrorDomain) { type = new ErrorType ((ErrorDomain) sym, null, unresolved_type.source_reference); } else if (sym is ErrorCode) { diff --git a/vala/valavaluetype.vala b/vala/valavaluetype.vala index 585337913..c881c1ed7 100644 --- a/vala/valavaluetype.vala +++ b/vala/valavaluetype.vala @@ -1,6 +1,6 @@ /* valavaluetype.vala * - * Copyright (C) 2007-2008 Jürg Billeter + * Copyright (C) 2007-2009 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 @@ -25,7 +25,7 @@ using GLib; /** * A value type, i.e. a struct or an enum type. */ -public class Vala.ValueType : DataType { +public abstract class Vala.ValueType : DataType { /** * The referred struct or enum. */ @@ -36,21 +36,6 @@ public class Vala.ValueType : DataType { data_type = type_symbol; } - public override DataType copy () { - var result = new ValueType (type_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 () { string ptr = ""; if (nullable) { diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index c698dbe3c..798cd48a7 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -30,6 +30,7 @@ [SimpleType] [CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE", type_signature = "b")] +[BooleanType] public struct bool { public string to_string () { if (this) {