implement camel_case_to_lower_case method extend string types support
authorJürg Billeter <j@bitron.ch>
Wed, 17 May 2006 20:57:09 +0000 (20:57 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 17 May 2006 20:57:09 +0000 (20:57 +0000)
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

svn path=/trunk/; revision=22

vala/ChangeLog
vala/bindings/GLib.vala
vala/vala/valanamespace.vala
vala/valac/generator.c

index ec5808e..171f47c 100644 (file)
@@ -1,5 +1,11 @@
 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
index ee8ad1e..4ddcdd1 100644 (file)
@@ -90,6 +90,8 @@ public struct uint64 {
 
 [CCode (cname = "gunichar")]
 public struct unichar {
+       [CCode (cname = "g_unichar_isupper")]
+       public bool isupper ();
 }
 
 [ReferenceType ()]
@@ -121,9 +123,19 @@ public struct string {
 [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*/);
 }
@@ -271,9 +283,10 @@ namespace GLib {
        [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;
        }
index 4ac09df..8098bae 100644 (file)
@@ -94,7 +94,38 @@ namespace Vala {
                }
 
                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 () {
index 0ed38ea..379d8a0 100644 (file)
@@ -393,6 +393,11 @@ vala_code_generator_find_static_type_of_expression (ValaCodeGenerator *generator
                        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) {
@@ -406,7 +411,7 @@ vala_code_generator_find_static_type_of_expression (ValaCodeGenerator *generator
                                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:
@@ -669,12 +674,14 @@ vala_code_generator_process_member_access (ValaCodeGenerator *generator, ValaExp
                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);
                }
        }