]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
support namespace attributes process namespace and class attributes use
authorJürg Billeter <j@bitron.ch>
Thu, 18 May 2006 12:42:42 +0000 (12:42 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 18 May 2006 12:42:42 +0000 (12:42 +0000)
2006-05-18  Jürg Billeter  <j@bitron.ch>

* vala/parser.y: support namespace attributes
* vala/valaattributeprocessor.vala: process namespace and class
  attributes
* vala/valacodegenerator.vala: use correct symbol names
* vala/valamethod.vala: add cname
* vala/valanamespace.vala: add cprefix, support cprefix attribute
* vala/valastruct.vala: prefix cname with namespace cprefix
* bindings/GLib.vala: add tolower to unichar
* valac/parser.y: rename namespace attribute cname to lower_case_cprefix

svn path=/trunk/; revision=24

vala/ChangeLog
vala/bindings/GLib.vala
vala/vala/parser.y
vala/vala/valaattributeprocessor.vala
vala/vala/valacodegenerator.vala
vala/vala/valamethod.vala
vala/vala/valanamespace.vala
vala/vala/valastruct.vala
vala/valac/parser.y

index c4873d4a44e5520aeb8aad80518095ad40d1294f..0d357ba666184509a3f3602393934609a160a2d6 100644 (file)
@@ -1,3 +1,15 @@
+2006-05-18  Jürg Billeter  <j@bitron.ch>
+
+       * vala/parser.y: support namespace attributes
+       * vala/valaattributeprocessor.vala: process namespace and class
+         attributes
+       * vala/valacodegenerator.vala: use correct symbol names
+       * vala/valamethod.vala: add cname
+       * vala/valanamespace.vala: add cprefix, support cprefix attribute
+       * vala/valastruct.vala: prefix cname with namespace cprefix
+       * bindings/GLib.vala: add tolower to unichar
+       * valac/parser.y: rename namespace attribute cname to lower_case_cprefix
+
 2006-05-18  Jürg Billeter  <j@bitron.ch>
 
        * update reference and property annotations
index 7ee6cc573f26815cf4fd86808136f34553d24ea2..5af0c036f590aa5498134c44c2152f67c0e5b6c6 100644 (file)
@@ -92,6 +92,8 @@ public struct uint64 {
 public struct unichar {
        [CCode (cname = "g_unichar_isupper")]
        public bool isupper ();
+       [CCode (cname = "g_unichar_tolower")]
+       public unichar tolower ();
 }
 
 [ReferenceType ()]
@@ -152,7 +154,7 @@ public struct string {
 }
 
 [Import ()]
-[CCode (cname = "g", cprefix = "G", include_filename = "glib.h")]
+[CCode (cprefix = "G", lower_case_cprefix = "g_", include_filename = "glib.h")]
 namespace GLib {
        public struct Path {
                public static ref string get_basename (string file_name);
index 48b008fbe7d55e1904d6bc4368cf0585757ab390..ed10b46147e623d99f0683deb125eda68679f5b9 100644 (file)
@@ -826,6 +826,7 @@ namespace_declaration
        : comment opt_attributes NAMESPACE IDENTIFIER
          {
                current_namespace = vala_namespace_new ($4, src_com (@4, $1));
+               VALA_CODE_NODE(current_namespace)->attributes = $2;
          }
          namespace_body
          {
index c74ed8e35c1591e93e1ddce1c0a0d50ae88166eb..6b3339ab9607a92eb734fe5c0f1d488d1ede9a45 100644 (file)
@@ -27,9 +27,17 @@ namespace Vala {
                public void process (CodeContext context) {
                        context.accept (this);
                }
+
+               public override void visit_begin_namespace (Namespace ns) {
+                       ns.process_attributes ();
+               }
        
                public override void visit_begin_struct (Struct st) {
                        st.process_attributes ();
                }
+       
+               public override void visit_begin_class (Class cl) {
+                       cl.process_attributes ();
+               }
        }
 }
index dcc98384acbcc8dde1515de589644b0bf1a99f7a..4b0e03c82077f168332eb21e791d921996acc2ea 100644 (file)
@@ -118,8 +118,8 @@ namespace Vala {
                }
                
                public override void visit_end_method (Method m) {
-                       var cmethod_decl = new CCodeFunction (name = m.name, return_type = "void");
-                       function = new CCodeFunction (name = m.name, return_type = "void");
+                       var cmethod_decl = new CCodeFunction (name = m.get_cname (), return_type = "void");
+                       function = new CCodeFunction (name = m.get_cname (), return_type = "void");
                        
                        if (m.access == MemberAccessibility.PUBLIC) {
                                header_type_member_declaration.append (cmethod_decl);
@@ -245,10 +245,14 @@ namespace Vala {
                public override void visit_literal_expression (LiteralExpression expr) {
                        expr.ccodenode = expr.literal.ccodenode;
                }
-
+               
                public override void visit_simple_name (SimpleName expr) {
-                       /* local variable */
-                       expr.ccodenode = new CCodeIdentifier (name = expr.name);
+                       if (expr.symbol_reference.node is Method) {
+                               var m = (Method) expr.symbol_reference.node;
+                               expr.ccodenode = new CCodeIdentifier (name = m.get_cname ());
+                       } else {
+                               expr.ccodenode = new CCodeIdentifier (name = expr.name);
+                       }
                }
 
                public override void visit_parenthesized_expression (ParenthesizedExpression expr) {
@@ -256,7 +260,12 @@ namespace Vala {
                }
 
                public override void visit_member_access (MemberAccess expr) {
-                       expr.ccodenode = new CCodeIdentifier (name = expr.member_name);
+                       if (expr.symbol_reference.node is Method) {
+                               var m = (Method) expr.symbol_reference.node;
+                               expr.ccodenode = new CCodeIdentifier (name = m.get_cname ());
+                       } else {
+                               expr.ccodenode = new CCodeIdentifier (name = expr.member_name);
+                       }
                }
 
                public override void visit_invocation_expression (InvocationExpression expr) {
index 9d41e241c6fc3a19abb5a5906233a411d3bd6d25..db47639263437221e66f7d8a2d73866c254587d1 100644 (file)
@@ -28,7 +28,7 @@ namespace Vala {
                public TypeReference return_type { get; construct; }
                public SourceReference source_reference { get; construct; }
                public weak CodeNode parent_type;
-               ref Statement _body;
+               Statement _body;
                public Statement body {
                        get {
                                return _body;
@@ -39,7 +39,10 @@ namespace Vala {
                }
                public MemberAccessibility access;
                public bool instance = true;
-               ref List<ref FormalParameter> parameters;
+               List<FormalParameter> parameters;
+               public string cname;
+               
+               Symbol dummy_symbol; // dummy type reference for broken dependency handling
                
                public static ref Method new (string name, TypeReference return_type, SourceReference source) {
                        return (new Method (name = name, return_type = return_type, source_reference = source));
@@ -66,6 +69,21 @@ namespace Vala {
                }
 
                public string get_cname () {
+                       if (cname == null) {
+                               var parent = symbol.parent_symbol.node;
+                               if (parent is Struct) {
+                                       cname = "%s_%s".printf (((Struct) parent).get_lower_case_cname (null), name);
+                               } else if (parent is Namespace) {
+                                       cname = "%s%s".printf (((Namespace) parent).get_lower_case_cprefix (), name);
+                               } else {
+                                       stderr.printf ("internal error: method is neither in struct nor in namespace\n");
+                               }
+                       }
+                       return cname;
+               }
+               
+               public void set_cname (string cname) {
+                       this.cname = cname;
                }
        }
 }
index a49fc742c4fc72f218e426d6e3a799cebe7144b0..b8a831f101524a5f842c0c5eff2031eae41d4522 100644 (file)
@@ -32,6 +32,7 @@ namespace Vala {
                List<Enum> enums;
                List<Field> fields;
                
+               public string cprefix;
                public string lower_case_cprefix;
                
                public static ref Namespace new (string name, SourceReference source) {
@@ -119,7 +120,7 @@ namespace Vala {
                                        }
                                }
                                
-                               result.append_unichar (c);
+                               result.append_unichar (c.tolower ());
                                
                                first = false;
                                i = i.next_char ();
@@ -128,6 +129,21 @@ namespace Vala {
                        return result.str;
                }
                
+               public string get_cprefix () {
+                       if (cprefix == null) {
+                               if (name == null) {
+                                       cprefix = "";
+                               } else {
+                                       cprefix = name;
+                               }
+                       }
+                       return cprefix;
+               }
+               
+               public void set_cprefix (string cprefix) {
+                       this.cprefix = cprefix;
+               }
+               
                public string get_lower_case_cprefix () {
                        if (lower_case_cprefix == null) {
                                if (name == null) {
@@ -142,5 +158,35 @@ namespace Vala {
                public void set_lower_case_cprefix (string cprefix) {
                        this.lower_case_cprefix = cprefix;
                }
+               
+               void process_ccode_attribute (Attribute a) {
+                       foreach (NamedArgument arg in a.args) {
+                               if (arg.name.collate ("cprefix") == 0) {
+                                       /* this will already be checked during semantic analysis */
+                                       if (arg.argument is LiteralExpression) {
+                                               var lit = ((LiteralExpression) arg.argument).literal;
+                                               if (lit is StringLiteral) {
+                                                       set_cprefix (((StringLiteral) lit).eval ());
+                                               }
+                                       }
+                               } else if (arg.name.collate ("lower_case_cprefix") == 0) {
+                                       /* this will already be checked during semantic analysis */
+                                       if (arg.argument is LiteralExpression) {
+                                               var lit = ((LiteralExpression) arg.argument).literal;
+                                               if (lit is StringLiteral) {
+                                                       set_lower_case_cprefix (((StringLiteral) lit).eval ());
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
+               public void process_attributes () {
+                       foreach (Attribute a in attributes) {
+                               if (a.name.collate ("CCode") == 0) {
+                                       process_ccode_attribute (a);
+                               }
+                       }
+               }
        }
 }
index e60d90be6f870e97b5bbc7cd322c239df6a6baa8..bb8b6bd4293d612e38f92c7e8d1d5951df90f62e 100644 (file)
@@ -88,7 +88,7 @@ namespace Vala {
                
                public override string get_cname () {
                        if (cname == null) {
-                               cname = name;
+                               cname = "%s%s".printf (@namespace.get_cprefix (), name);
                        }
                        return cname;
                }
index 9f22187e51a3d930b20e0022313cfb0dfca53225..16c1e96daa89ece2f0b58de3829368639d05eae1 100644 (file)
@@ -376,8 +376,8 @@ namespace_declaration
                                for (al = anno->argument_list; al != NULL; al = al->next) {
                                        ValaNamedArgument *arg = al->data;
                                        
-                                       if (strcmp (arg->name, "cname") == 0) {
-                                               current_namespace->lower_case_cname = g_strdup_printf ("%s_", eval_string (arg->expression->str));
+                                       if (strcmp (arg->name, "lower_case_cprefix") == 0) {
+                                               current_namespace->lower_case_cname = g_strdup (eval_string (arg->expression->str));
                                                current_namespace->upper_case_cname = g_ascii_strup (current_namespace->lower_case_cname, -1);
                                        } else if (strcmp (arg->name, "cprefix") == 0) {
                                                current_namespace->cprefix = eval_string (arg->expression->str);