2006-05-17 Jürg Billeter <j@bitron.ch>
+ * vala/valanamespace.vala: implement camel_case_to_lower_case method
+ * bindings/GLib.vala: extend string types
+ * valac/generator.c: support access to struct fields
+
+2006-05-17 Jürg Billeter <j@bitron.ch>
+
* vala/parser.y: support variable declarators, subtyping, constants,
properties, and enums
* vala/valacodevisitor.vala: support formal parameters, property
[CCode (cname = "gunichar")]
public struct unichar {
+ [CCode (cname = "g_unichar_isupper")]
+ public bool isupper ();
}
[ReferenceType ()]
[ReferenceType ()]
[CCode (cname = "char")]
public struct ustring {
+ [CCode (cname = "g_strndup")]
+ public ref ustring ndup (int n);
+ [CCode (cname = "g_strcompress")]
+ public ref ustring compress ();
+ [CCode (cname = "g_utf8_next_char")]
+ public ustring next_char ();
+ [CCode (cname = "g_utf8_get_char")]
+ public unichar get_char ();
[CCode (cname = "g_utf8_offset_to_pointer")]
[PlusOperator ()]
- public string offset (long offset);
+ public ustring offset (long offset);
+ [CCode (cname = "g_utf8_prev_char")]
+ public ustring prev_char ();
[CCode (cname = "g_utf8_strlen")]
public long len (long max /*= -1*/);
}
[ReferenceType ()]
public struct String {
public static ref String new (string init);
- public static void append_c (char c);
+ public void append_c (char c);
+ public void append_unichar (unichar wc);
- public ref string str;
+ public ref ustring str;
public long len;
public long allocated_len;
}
}
public static ref string camel_case_to_lower_case (string camel_case) {
- return camel_case.down (-1);
+ String result = String.new ("");
+
+ ustring i = camel_case;
+
+ bool first = true;
+ while (i.len (-1) > 0) {
+ unichar c = i.get_char ();
+ if (c.isupper () && !first) {
+ /* current character is upper case and
+ * we're not at the beginning */
+ ustring t = i.prev_char ();
+ bool prev_upper = t.get_char ().isupper ();
+ t = i.next_char ();
+ bool next_upper = t.get_char ().isupper ();
+ if (!prev_upper || (i.len (-1) >= 2 && !next_upper)) {
+ /* previous character wasn't upper case or
+ * next character isn't upper case*/
+ int len = result.str.len (-1);
+ if (len != 1 && result.str.offset (len - 2).get_char () != '_') {
+ /* we're not creating 1 character words */
+ result.append_c ('_');
+ }
+ }
+ }
+
+ result.append_unichar (c);
+
+ first = false;
+ i = i.next_char ();
+ }
+
+ return result.str;
}
public string get_lower_case_cprefix () {
if (expr->static_type_symbol == NULL) {
err (expr->member_access.left->location, "error: struct member ´%s´ not found", expr->member_access.right);
}
+ if (expr->static_type_symbol->type == VALA_SYMBOL_TYPE_FIELD) {
+ expr->field = expr->static_type_symbol->field;
+ expr->array_type = expr->static_type_symbol->field->declaration_statement->variable_declaration->type->array_type;
+ expr->static_type_symbol = expr->static_type_symbol->field->declaration_statement->variable_declaration->type->symbol;
+ }
} else if (sym != NULL && sym->type == VALA_SYMBOL_TYPE_ENUM) {
expr->static_symbol = g_hash_table_lookup (sym->symbol_table, expr->member_access.right);
if (expr->static_symbol == NULL) {
err (expr->member_access.left->location, "error: namespace member ´%s´ not found", expr->member_access.right);
}
} else {
- err (expr->member_access.left->location, "error: specified expression type %d can't be used for member access", sym->type);
+ err (expr->member_access.left->location, "error: specified symbol type %d can't be used for member access", sym->type);
}
break;
case VALA_EXPRESSION_TYPE_OBJECT_CREATION:
vala_code_generator_process_expression (generator, expr->member_access.left);
fprintf (generator->c_file, ")");
} else {
- if (expr->field != NULL) {
+ if (expr->field != NULL && !expr->field->is_struct_field) {
fprintf (generator->c_file, "%s%s(", expr->field->class->namespace->upper_case_cname, expr->field->class->upper_case_cname);
}
vala_code_generator_process_expression (generator, expr->member_access.left);
if (expr->field != NULL) {
- fprintf (generator->c_file, ")");
+ if (!expr->field->is_struct_field) {
+ fprintf (generator->c_file, ")");
+ }
fprintf (generator->c_file, "->%s", expr->member_access.right);
}
}