vala r1163 - in trunk: . vala



Author: juergbi
Date: Sun Mar 30 20:09:57 2008
New Revision: 1163
URL: http://svn.gnome.org/viewvc/vala?rev=1163&view=rev

Log:
2008-03-30  Juerg Billeter  <j bitron ch>

	* vala/valasemanticanalyzer.vala: enhance support for pointer
	  arithmetic


Modified:
   trunk/ChangeLog
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Sun Mar 30 20:09:57 2008
@@ -44,6 +44,7 @@
 	DataType int_type;
 	DataType uint_type;
 	DataType ulong_type;
+	DataType size_t_type;
 	DataType unichar_type;
 	DataType type_type;
 	Typesymbol pointer_type;
@@ -86,6 +87,7 @@
 		int_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("int"));
 		uint_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("uint"));
 		ulong_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("ulong"));
+		size_t_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("size_t"));
 		unichar_type = new ValueType ((Typesymbol) root_symbol.scope.lookup ("unichar"));
 
 		// TODO: don't require GLib namespace in semantic analyzer
@@ -2547,9 +2549,12 @@
 				if (offset_type != null && offset_type.is_integer_type ()) {
 					if (expr.operator == BinaryOperator.PLUS
 					    || expr.operator == BinaryOperator.MINUS) {
-						// pointer arithmetic
+						// pointer arithmetic: pointer +/- offset
 						expr.static_type = expr.left.static_type.copy ();
 					}
+				} else if (expr.right.static_type is PointerType) {
+					// pointer arithmetic: pointer - pointer
+					expr.static_type = size_t_type;
 				}
 			}
 
@@ -2580,6 +2585,8 @@
 			if (expr.left.static_type.compatible (string_type)
 			    && expr.right.static_type.compatible (string_type)) {
 				// string comparison
+				} else if (expr.left.static_type is PointerType && expr.right.static_type is PointerType) {
+					// pointer arithmetic
 			} else {
 				var resulting_type = get_arithmetic_result_type (expr.left.static_type, expr.right.static_type);
 



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