]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add BooleanType, EnumValueType, FloatingType, and StructValueType as
authorJürg Billeter <j@bitron.ch>
Sat, 3 Jan 2009 14:02:48 +0000 (14:02 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 3 Jan 2009 14:02:48 +0000 (14:02 +0000)
2009-01-03  Jürg Billeter  <j@bitron.ch>

* 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

23 files changed:
ChangeLog
gobject/valaccodebasemodule.vala
gobject/valaccodemethodmodule.vala
vala/Makefile.am
vala/valaarraytype.vala
vala/valabinaryexpression.vala
vala/valabooleantype.vala [new file with mode: 0644]
vala/valacharacterliteral.vala
vala/valadostatement.vala
vala/valaenum.vala
vala/valaenumvaluetype.vala [new file with mode: 0644]
vala/valaerrordomain.vala
vala/valafloatingtype.vala [new file with mode: 0644]
vala/valaintegerliteral.vala
vala/valaintegertype.vala
vala/valaobjectcreationexpression.vala
vala/valarealliteral.vala
vala/valasemanticanalyzer.vala
vala/valastruct.vala
vala/valastructvaluetype.vala [new file with mode: 0644]
vala/valasymbolresolver.vala
vala/valavaluetype.vala
vapi/glib-2.0.vapi

index b6fe9af509059c0c63ef9e72a60909feed6100c5..f8bbf99166c9f3be34dacd1a9ad2349c26d5f4b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2009-01-03  Jürg Billeter  <j@bitron.ch>
+
+       * 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  <j@bitron.ch>
 
        * vapi/packages/gdk-2.0/gdk-2.0.metadata:
index c3378f7a331a1b097afffbc6b730b1900055887f..25d169374f1a4a497f458f89e29a861fa1c1d105 100644 (file)
@@ -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) {
index fc7b082c5f94116310a744577d4708d04f202c1e..b66bb2d34ea7f50a8fb882f886def4dc4aac5731 100644 (file)
@@ -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;
index 736379650fb8cf114474b27b2421492ab582ec0c..4579a372d4c39aa297125b9670df9f5a7b53ede4 100644 (file)
@@ -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 \
index 946c28274781c222409db49ed6f521c198274e10..7345e4663fc395c424cc1463cf31cd0f151730f5 100644 (file)
@@ -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));
index f7d4dd653787c18d2da602e77a53a25efddd8084..66ecabe4bee091bd332c5910c1321dd83d58aa3f 100644 (file)
@@ -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 (file)
index 0000000..b224a93
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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;
+       }
+}
index 019439fe7c99ab71dd67f96d9848702db2c8c171..1d33c92ef1cf2e45cc24dbda16f6226cb6aa7a3b 100644 (file)
@@ -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;
        }
index c994cb148e083be419b78588a8a29ec0cbff512d..efc2d7acd9df74f39eef706f5c18d964c3d02e5c 100644 (file)
@@ -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;
index 56eca2b2f9ee2a50dd141204bee5901244f03c01..4f2a73ee5c1eb31f6d8405f7eb8854fcaf13d3b0 100644 (file)
@@ -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 (file)
index 0000000..bf138b0
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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;
+       }
+}
index 92ec0b39be0646db7e5b395bc0a723f546cb9ee1..713e452ed69f0897150e48b92b310c91eb5b7a86 100644 (file)
@@ -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 (file)
index 0000000..83c4abe
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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;
+       }
+}
index 73a2910de10c659bb63e44a65806ecb4ce7dd82c..95fd132833403d7a84e2ea6b91430ff6131c9ef5 100644 (file)
@@ -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;
        }
index 88eee0390972cde781b6f3a5702fc6153d9c5e75..2c04491b071ff31bf02803305a96c19b2430c647 100644 (file)
@@ -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) {
index 9fc43fd10ab4556f113eb40786fdafd85b70b3f8..c86539fba24208a32f015c58098d815e769c1de1 100644 (file)
@@ -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;
index 19d598da888cbf632efd0545ac7f73164910f36a..cbfca7c05da6425dc4cfe0acb4f9d3229a675fc1 100644 (file)
@@ -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;
        }
index 9e6e4e7f7bb41002031f5e07cb46d446429b74ff..f6e8588e7fdcbb018c2d13446a3c3e939aa7630d 100644 (file)
@@ -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) {
index 6595f0cc79d372d64a733c581cb41c7e575ed000..5c07de00eb58c73f9bd8fedf7264ea60a045909a 100644 (file)
@@ -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 (file)
index 0000000..dce8fca
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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;
+       }
+}
index 7ce0055e461e8d11b47132cadc4d344521acb2c0..be43079f2dae1eb04521dc02c742fd5e73399ba2 100644 (file)
@@ -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) {
index 585337913a730fc9eb6e31047e569769548eefa6..c881c1ed7eab79de44a431f5902e0fb3e8655d08 100644 (file)
@@ -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) {
index c698dbe3cc0e4d05485e47bcf6a68d30cbe1d9ad..798cd48a791eca5b7b689836949f98f8b3aae3d0 100644 (file)
@@ -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) {