+2008-03-30 Jürg Billeter <j@bitron.ch>
+
+ * vala/valasemanticanalyzer.vala: enhance support for pointer
+ arithmetic
+
2008-03-29 Jürg Billeter <j@bitron.ch>
* vala/parser.y, vala/valaclass.vala, vala/valaconstructor.vala,
DataType int_type;
DataType uint_type;
DataType ulong_type;
+ DataType size_t_type;
DataType unichar_type;
DataType type_type;
Typesymbol pointer_type;
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
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;
}
}
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);