+2007-07-11 Jürg Billeter <j@bitron.ch>
+
+ * vala/valasemanticanalyzer.vala, gobject/valacodegenerator.vala:
+ support element access for strings
+ * tests/test-019.vala, tests/test-019.out: test element access for
+ strings
+
+ Fixes bug 443523
+
2007-07-11 Jürg Billeter <j@bitron.ch>
* ccode/valaccodefragment.vala, ccode/valaccodenode.vala,
int rank = indices.length ();
if (rank == 1) {
- /* FIXME: had to add Expression cast due to possible compiler bug */
- expr.ccodenode = new CCodeElementAccess ((CCodeExpression)expr.container.ccodenode, (CCodeExpression)((Expression)indices.first ().data).ccodenode);
+ var ccontainer = (CCodeExpression) expr.container.ccodenode;
+ // FIXME had to add Expression cast due to possible compiler bug
+ var cindex = (CCodeExpression) ((Expression) indices.first ().data).ccodenode;
+
+ if (expr.container.static_type.data_type == string_type.data_type) {
+ // access to unichar in a string
+ var coffsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_offset_to_pointer"));
+ coffsetcall.add_argument (ccontainer);
+ coffsetcall.add_argument (cindex);
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_get_char"));
+ ccall.add_argument (coffsetcall);
+
+ expr.ccodenode = ccall;
+ } else {
+ // access to element in an array
+ expr.ccodenode = new CCodeElementAccess (ccontainer, cindex);
+ }
} else {
expr.error = true;
Report.error (expr.source_reference, "Arrays with more then one dimension are not supported yet");
-Element access: 1 2 3 4 5 6 7 8 9
+Element access: 1 2 3 4 5 6 7 8 9 10 11 12 13
stdout.printf (" 2");
var sa = "a,b,c,d".split (",");
- var i = 3;
+ int i = 3;
stdout.printf (" 3");
stdout.printf (" 7");
}
- stdout.printf (" 8");
+ string bar = "efgh";
+ counter = 0;
+ if (bar[inc()] == 'e') {
+ stdout.printf (" 8");
+ }
+ if (bar[inc()] == 'f') {
+ stdout.printf (" 9");
+ }
+ if (bar[2] == 'g') {
+ stdout.printf (" 10");
+ }
+ if (bar[i] == 'h') {
+ stdout.printf (" 11");
+ }
+
+
+ stdout.printf (" 12");
}
public int inc () {
var foo = new Foo ();
foo.run ();
- stdout.printf (" 9\n");
+ stdout.printf (" 13\n");
return 0;
}
TypeReference int_type;
TypeReference uint_type;
TypeReference ulong_type;
+ TypeReference unichar_type;
TypeReference type_type;
DataType pointer_type;
DataType initially_unowned_type;
ulong_type = new TypeReference ();
ulong_type.data_type = (DataType) root_symbol.lookup ("ulong").node;
+ unichar_type = new TypeReference ();
+ unichar_type.data_type = (DataType) root_symbol.lookup ("unichar").node;
+
// TODO: don't require GLib namespace in semantic analyzer
var glib_ns = root_symbol.lookup ("GLib");
if (glib_ns != null) {
}
expr.static_type = (TypeReference) args.data;
+ } else if (expr.container.static_type.data_type == string_type.data_type) {
+ if (expr.get_indices ().length () != 1) {
+ expr.error = true;
+ Report.error (expr.source_reference, "Element access with more than one dimension is not supported for strings");
+ return;
+ }
+
+ expr.static_type = unichar_type;
} else {
expr.error = true;
Report.error (expr.source_reference, "The expression `%s' does not denote an Array".printf (expr.container.static_type.to_string ()));