vala r888 - in trunk: . vala vapi



Author: juergbi
Date: Tue Jan 22 20:32:31 2008
New Revision: 888
URL: http://svn.gnome.org/viewvc/vala?rev=888&view=rev

Log:
2008-01-22  Juerg Billeter  <j bitron ch>

	* vala/Makefile.am, vala/valaintegertype.vala,
	  vala/valasemanticanalyzer.vala, vapi/glib-2.0.vapi: improve implicit
	  conversion from integer literals, fixes bug 492475


Added:
   trunk/vala/valaintegertype.vala
Modified:
   trunk/ChangeLog
   trunk/vala/Makefile.am
   trunk/vala/valasemanticanalyzer.vala
   trunk/vapi/glib-2.0.vapi

Modified: trunk/vala/Makefile.am
==============================================================================
--- trunk/vala/Makefile.am	(original)
+++ trunk/vala/Makefile.am	Tue Jan 22 20:32:31 2008
@@ -64,6 +64,7 @@
 	valainitializerlist.vala \
 	valainstancecast.vala \
 	valaintegerliteral.vala \
+	valaintegertype.vala \
 	valainterface.vala \
 	valainterfacetype.vala \
 	valainterfacewriter.vala \

Added: trunk/vala/valaintegertype.vala
==============================================================================
--- (empty file)
+++ trunk/vala/valaintegertype.vala	Tue Jan 22 20:32:31 2008
@@ -0,0 +1,52 @@
+/* valaintegertype.vala
+ *
+ * Copyright (C) 2008  JÃrg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	JÃrg Billeter <j bitron ch>
+ */
+
+using GLib;
+
+/**
+ * An integer type.
+ */
+public class Vala.IntegerType : ValueType {
+	public IntegerLiteral literal { get; set; }
+
+	public IntegerType (construct Typesymbol! type_symbol) {
+		data_type = type_symbol;
+	}
+
+	public override bool compatible (DataType! target_type) {
+		if (target_type.data_type is Struct && literal.get_type_name () == "int") {
+			// int literals are implicitly convertible to integer types
+			// of a lower rank if the value of the literal is within
+			// the range of the target type
+			var target_st = (Struct) target_type.data_type;
+			if (target_st.is_integer_type ()) {
+				var int_attr = target_st.get_attribute ("IntegerType");
+				if (int_attr.has_argument ("min") && int_attr.has_argument ("max")) {
+					int val = literal.value.to_int ();
+					return (val >= int_attr.get_integer ("min") && val <= int_attr.get_integer ("max"));
+				}
+			}
+		}
+
+		return base.compatible (target_type);
+	}
+}

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Tue Jan 22 20:32:31 2008
@@ -1216,7 +1216,9 @@
 	}
 
 	public override void visit_integer_literal (IntegerLiteral! expr) {
-		expr.static_type = new ValueType ((Typesymbol) root_symbol.scope.lookup (expr.get_type_name ()));
+		var int_type = new IntegerType ((Typesymbol) root_symbol.scope.lookup (expr.get_type_name ()));
+		int_type.literal = expr;
+		expr.static_type = int_type;
 	}
 
 	public override void visit_real_literal (RealLiteral! expr) {

Modified: trunk/vapi/glib-2.0.vapi
==============================================================================
--- trunk/vapi/glib-2.0.vapi	(original)
+++ trunk/vapi/glib-2.0.vapi	Tue Jan 22 20:32:31 2008
@@ -47,7 +47,7 @@
 
 [SimpleType]
 [CCode (cname = "gchar", cprefix = "g_ascii_", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "\'\\0\'")]
-[IntegerType (rank = 2)]
+[IntegerType (rank = 2, min = 0, max = 127)]
 public struct char {
 	[InstanceLast ()]
 	[CCode (cname = "g_strdup_printf")]
@@ -71,7 +71,7 @@
 
 [SimpleType]
 [CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "\'\\0\'")]
-[IntegerType (rank = 3)]
+[IntegerType (rank = 3, min = 0, max = 255)]
 public struct uchar {
 	[InstanceLast ()]
 	[CCode (cname = "g_strdup_printf")]
@@ -120,7 +120,7 @@
 
 [SimpleType]
 [CCode (cname = "gshort", cheader_filename = "glib.h", default_value = "0")]
-[IntegerType (rank = 4)]
+[IntegerType (rank = 4, min = -32768, max = 32767)]
 public struct short {
 	[CCode (cname = "G_MINSHORT")]
 	public static short MIN;
@@ -134,7 +134,7 @@
 
 [SimpleType]
 [CCode (cname = "gushort", cheader_filename = "glib.h", default_value = "0U")]
-[IntegerType (rank = 5)]
+[IntegerType (rank = 5, min = 0, max = 65535)]
 public struct ushort {
 	[CCode (cname = "0U")]
 	public static ushort MIN;
@@ -207,7 +207,7 @@
 
 [SimpleType]
 [CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0")]
-[IntegerType (rank = 1)]
+[IntegerType (rank = 1, min = -128, max = 127)]
 public struct int8 {
 	[CCode (cname = "G_MININT8")]
 	public static int8 MIN;
@@ -220,7 +220,7 @@
 
 [SimpleType]
 [CCode (cname = "guint8", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "0U")]
-[IntegerType (rank = 3)]
+[IntegerType (rank = 3, min = 0, max = 255)]
 public struct uint8 {
 	[CCode (cname = "0U")]
 	public static uint8 MIN;
@@ -233,7 +233,7 @@
 
 [SimpleType]
 [CCode (cname = "gint16", cheader_filename = "glib.h", default_value = "0")]
-[IntegerType (rank = 4)]
+[IntegerType (rank = 4, min = -32768, max = 32767)]
 public struct int16 {
 	[CCode (cname = "G_MININT16")]
 	public static int16 MIN;
@@ -246,7 +246,7 @@
 
 [SimpleType]
 [CCode (cname = "guint16", cheader_filename = "glib.h", default_value = "0U")]
-[IntegerType (rank = 5)]
+[IntegerType (rank = 5, min = 0, max = 65535)]
 public struct uint16 {
 	[CCode (cname = "0U")]
 	public static uint16 MIN;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]