summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuerg Billeter <j@bitron.ch>2008-03-30 19:09:57 +0000
committerJürg Billeter <juergbi@src.gnome.org>2008-03-30 19:09:57 +0000
commit71275f71cb6e558588e341af6376d5e0e3a97282 (patch)
tree6804a96cea80a3b2818d10e0b5811434fbf0475a
parent5813064bb1a2ea57d23f50a22fcd82fb1dd41c7e (diff)
downloadvala-71275f71cb6e558588e341af6376d5e0e3a97282.tar.gz
enhance support for pointer arithmetic
2008-03-30 Juerg Billeter <j@bitron.ch> * vala/valasemanticanalyzer.vala: enhance support for pointer arithmetic svn path=/trunk/; revision=1163
-rw-r--r--ChangeLog5
-rw-r--r--vala/valasemanticanalyzer.vala9
2 files changed, 13 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b204817b9..684155e3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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,
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 8d144d34d..4c429141e 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -44,6 +44,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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);