]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
separate declaration output remove comma at end of enum remove unused
authorJürg Billeter <j@bitron.ch>
Thu, 10 May 2007 11:33:08 +0000 (11:33 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 10 May 2007 11:33:08 +0000 (11:33 +0000)
2007-05-10  Jürg Billeter  <j@bitron.ch>

* ccode/valaccodeblock.vala, ccode/valaccodedeclaration.vala,
  ccode/valaccodedeclarator.vala, ccode/valaccodefragment.vala,
  ccode/valaccodefunctiondeclarator.vala, ccode/valaccodenode.vala,
  ccode/valaccodeoncesection.vala, ccode/valaccodestruct.vala,
  ccode/valaccodetypedefinition.vala,
  ccode/valaccodevariabledeclarator.vala: separate declaration output
* vala/parser.y: remove comma at end of enum
* vala/valaclass.vala, vala/valastruct.vala: remove unused methods
* vala/Makefile.am: update
* gobject/valacodegeneratorsourcefile.vala: support declaration
  separation in C code
* gobject/valaclassregisterfunction.vala,
  gobject/valainterfaceregisterfunction.vala,
  gobject/valatyperegisterfunction.vala: move from vala directory,
  move interface info declarations to the beginning of the block
* gobject/Makefile.am: update

svn path=/trunk/; revision=315

20 files changed:
ChangeLog
ccode/valaccodeblock.vala
ccode/valaccodedeclaration.vala
ccode/valaccodedeclarator.vala
ccode/valaccodefragment.vala
ccode/valaccodefunctiondeclarator.vala
ccode/valaccodenode.vala
ccode/valaccodeoncesection.vala
ccode/valaccodestruct.vala
ccode/valaccodetypedefinition.vala
ccode/valaccodevariabledeclarator.vala
gobject/Makefile.am
gobject/valaclassregisterfunction.vala [moved from vala/valaclassregisterfunction.vala with 89% similarity]
gobject/valacodegeneratorsourcefile.vala
gobject/valainterfaceregisterfunction.vala [moved from vala/valainterfaceregisterfunction.vala with 100% similarity]
gobject/valatyperegisterfunction.vala [moved from vala/valatyperegisterfunction.vala with 95% similarity]
vala/Makefile.am
vala/parser.y
vala/valaclass.vala
vala/valastruct.vala

index 17929c402b49ed129f6dff2ecab04611003d1358..dd818eeaea05638deeb184e02cfbd727c8d3a102 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2007-05-10  Jürg Billeter  <j@bitron.ch>
+
+       * ccode/valaccodeblock.vala, ccode/valaccodedeclaration.vala,
+         ccode/valaccodedeclarator.vala, ccode/valaccodefragment.vala,
+         ccode/valaccodefunctiondeclarator.vala, ccode/valaccodenode.vala,
+         ccode/valaccodeoncesection.vala, ccode/valaccodestruct.vala,
+         ccode/valaccodetypedefinition.vala,
+         ccode/valaccodevariabledeclarator.vala: separate declaration output
+       * vala/parser.y: remove comma at end of enum
+       * vala/valaclass.vala, vala/valastruct.vala: remove unused methods
+       * vala/Makefile.am: update
+       * gobject/valacodegeneratorsourcefile.vala: support declaration
+         separation in C code
+       * gobject/valaclassregisterfunction.vala,
+         gobject/valainterfaceregisterfunction.vala,
+         gobject/valatyperegisterfunction.vala: move from vala directory,
+         move interface info declarations to the beginning of the block
+       * gobject/Makefile.am: update
+
 2007-05-09  Jürg Billeter  <j@bitron.ch>
 
        * ccode/valaccodeenum.vala: remove comma at end of generated enumerator
index 3e593ce4e000a54072a297fefd756b10191dd184..3421099455d601ceb47c1edb1d8c78290222d32e 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodeblock.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,6 +51,9 @@ public class Vala.CCodeBlock : CCodeStatement {
        
        public override void write (CCodeWriter! writer) {
                writer.write_begin_block ();
+               foreach (CCodeNode statement in statements) {
+                       statement.write_declaration (writer);
+               }
                foreach (CCodeNode statement in statements) {
                        statement.write (writer);
                }
index 8112a0cf48d9eaf00489889804730239e79b089a..c0d8605effebe5e3fdd47c36086ef8cf54932652 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodedeclaration.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -52,10 +52,39 @@ public class Vala.CCodeDeclaration : CCodeStatement {
        }
        
        public override void write (CCodeWriter! writer) {
-               writer.write_indent ();
                if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) {
+                       // combined declaration and initialization for static variables
+                       writer.write_indent ();
                        writer.write_string ("static ");
+                       writer.write_string (type_name);
+                       writer.write_string (" ");
+               
+                       bool first = true;
+                       foreach (CCodeDeclarator decl in declarators) {
+                               if (!first) {
+                                       writer.write_string (", ");
+                               } else {
+                                       first = false;
+                               }
+                               decl.write (writer);
+                       }
+
+                       writer.write_string (";");
+                       writer.write_newline ();
+               } else {
+                       foreach (CCodeDeclarator decl in declarators) {
+                               decl.write_initialization (writer);
+                       }
+               }
+       }
+
+       public override void write_declaration (CCodeWriter! writer) {
+               if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) {
+                       // no separate declaration for static variables
+                       return;
                }
+
+               writer.write_indent ();
                if ((modifiers & CCodeModifiers.REGISTER) == CCodeModifiers.REGISTER) {
                        writer.write_string ("register ");
                }
@@ -69,7 +98,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                        } else {
                                first = false;
                        }
-                       decl.write (writer);
+                       decl.write_declaration (writer);
                }
 
                writer.write_string (";");
index 8b63f0bfe03708b394712912253f74d76bb854f7..e7cdcbe8362f88128dd4257199b8a01b9746935f 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodedeclarator.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,4 +26,12 @@ using GLib;
  * Represents a variable or function pointer declarator in the C code.
  */
 public abstract class Vala.CCodeDeclarator : CCodeNode {
+       /**
+        * Writes initialization statements for this declarator with the
+        * specified C code writer if necessary.
+        *
+        * @param writer a C code writer
+        */
+       public virtual void write_initialization (CCodeWriter! writer) {
+       }
 }
index ef578b0d37bd3de87e79452ddf659f2c4d90692c..6f2e05bbfeb0ea4454e4718ee3a5f20521d7fca5 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodefragment.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,4 +51,10 @@ public class Vala.CCodeFragment : CCodeNode {
                        node.write (writer);
                }
        }
+
+       public override void write_declaration (CCodeWriter! writer) {
+               foreach (CCodeNode node in children) {
+                       node.write_declaration (writer);
+               }
+       }
 }
index cc6ef2e51eb9770df640932e956bf952529abbc7..663456f24328f66ce5d282e57b300801a9b8059b 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodefunctiondeclarator.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -47,6 +47,10 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
        }
        
        public override void write (CCodeWriter! writer) {
+               write_declaration (writer);
+       }
+       
+       public override void write_declaration (CCodeWriter! writer) {
                writer.write_string ("(*");
                writer.write_string (name);
                writer.write_string (") (");
index e3a28ee2dd610a58c7be5d5fdc8a51bad3ff7c93..77c66d420df87167f726d4729a40e6b012eabdcd 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodenode.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,4 +39,13 @@ public abstract class Vala.CCodeNode {
         * @param writer a C code writer
         */
        public abstract void write (CCodeWriter! writer);
+
+       /**
+        * Writes declaration for this code node with the specified C code
+        * writer if necessary.
+        *
+        * @param writer a C code writer
+        */
+       public virtual void write_declaration (CCodeWriter! writer) {
+       }
 }
index 831e025b8a07e6c6681a919741452890a3d4d4ad..5d0ceff349bdede73d340f20da5990ad32bf43a6 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodeoncesection.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -43,6 +43,9 @@ public class Vala.CCodeOnceSection : CCodeFragment {
                writer.write_string ("#define ");
                writer.write_string (define);
                writer.write_newline ();
+               foreach (CCodeNode node in get_children ()) {
+                       node.write_declaration (writer);
+               }
                foreach (CCodeNode node in get_children ()) {
                        node.write (writer);
                }
@@ -50,4 +53,7 @@ public class Vala.CCodeOnceSection : CCodeFragment {
                writer.write_string ("#endif");
                writer.write_newline ();
        }
+       
+       public override void write_declaration (CCodeWriter! writer) {
+       }
 }
index e11d67ec583eaa2fcfb2fa1e12579ae4f2242db7..30e6be2d3b1fa6dacafa8fcf98899a7c659aa79d 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodestruct.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -63,7 +63,7 @@ public class Vala.CCodeStruct : CCodeNode {
                writer.write_string (name);
                writer.write_begin_block ();
                foreach (CCodeDeclaration decl in declarations) {
-                       decl.write (writer);
+                       decl.write_declaration (writer);
                }
                writer.write_end_block ();
                writer.write_string (";");
index 5ef085ba44a578db10250d3da804e1061826fc95..dd82a78b9bdf19a58653568da15cac9901c22857 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodetypedefinition.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,6 +42,9 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
        }
        
        public override void write (CCodeWriter! writer) {
+       }
+       
+       public override void write_declaration (CCodeWriter! writer) {
                writer.write_indent ();
                writer.write_string ("typedef ");
                
@@ -49,7 +52,7 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
                
                writer.write_string (" ");
                
-               declarator.write (writer);
+               declarator.write_declaration (writer);
                
                writer.write_string (";");
                writer.write_newline ();
index 5a3fc2d43b2217a499086bcdc5da19913206efab..790b776d70784ea9d3282d40779c2694e5dc2182 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodevariabledeclarator.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -44,13 +44,30 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
                name = _name;
                initializer = init;
        }
-       
+
        public override void write (CCodeWriter! writer) {
                writer.write_string (name);
-               
+
+               if (initializer != null) {
+                       writer.write_string (" = ");
+                       initializer.write (writer);
+               }
+       }
+
+       public override void write_declaration (CCodeWriter! writer) {
+               writer.write_string (name);
+       }
+
+       public override void write_initialization (CCodeWriter! writer) {
                if (initializer != null) {
+                       writer.write_indent ();
+
+                       writer.write_string (name);
                        writer.write_string (" = ");
                        initializer.write (writer);
+
+                       writer.write_string (";");
+                       writer.write_newline ();
                }
        }
 }
index 2101f5ee08ca4ae7fbab2a904149ddaff3124da4..ff4ea8044063225fe4debf463d478c86438f3523 100644 (file)
@@ -12,6 +12,9 @@ lib_LTLIBRARIES = \
 
 libvala_la_SOURCES = \
        gobject.vala.stamp \
+       valaclassregisterfunction.c \
+       valaclassregisterfunction.h \
+       valaclassregisterfunction.vala \
        valacodegenerator.c \
        valacodegenerator.h \
        valacodegenerator.vala \
@@ -42,11 +45,18 @@ libvala_la_SOURCES = \
        valacodegeneratorstruct.c \
        valacodegeneratorstruct.h \
        valacodegeneratorstruct.vala \
+       valainterfaceregisterfunction.c \
+       valainterfaceregisterfunction.h \
+       valainterfaceregisterfunction.vala \
+       valatyperegisterfunction.c \
+       valatyperegisterfunction.h \
+       valatyperegisterfunction.vala \
        $(NULL)
 
 gobjectincludedir = $(includedir)/vala-1.0/gobject
 
 gobjectinclude_HEADERS = \
+       valaclassregisterfunction.h \
        valacodegenerator.h \
        valacodegeneratorassignment.h \
        valacodegeneratorclass.h \
@@ -57,6 +67,8 @@ gobjectinclude_HEADERS = \
        valacodegeneratorsignal.h \
        valacodegeneratorsourcefile.h \
        valacodegeneratorstruct.h \
+       valainterfaceregisterfunction.h \
+       valatyperegisterfunction.h \
        $(NULL)
 
 gobject.vala gobject.vala.stamp: $(filter %.vala,$(libvala_la_SOURCES))
similarity index 89%
rename from vala/valaclassregisterfunction.vala
rename to gobject/valaclassregisterfunction.vala
index 607a049949d6d6f37dd9e34003bd2b2ef00e556d..29d96ed7fcda0bce9cd591452835864f1fdb158f 100644 (file)
@@ -77,7 +77,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
                }
        }
 
-       public override ref CCodeFragment! get_type_interface_init_statements () {
+       public override ref CCodeFragment! get_type_interface_init_declaration () {
                var frag = new CCodeFragment ();
                
                foreach (TypeReference base_type in class_reference.get_base_types ()) {
@@ -93,6 +93,23 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
                        ctypedecl.modifiers = CCodeModifiers.STATIC;
                        ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer (iface_info_name, new CCodeConstant ("{ (GInterfaceInitFunc) %s_%s_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}".printf (class_reference.get_lower_case_cname (null), iface.get_lower_case_cname (null)))));
                        frag.append (ctypedecl);
+               }
+               
+               return frag;
+       }
+
+       public override ref CCodeFragment! get_type_interface_init_statements () {
+               var frag = new CCodeFragment ();
+               
+               foreach (TypeReference base_type in class_reference.get_base_types ()) {
+                       if (!(base_type.data_type is Interface)) {
+                               continue;
+                       }
+                       
+                       var iface = (Interface) base_type.data_type;
+                       
+                       var iface_info_name = "%s_info".printf (iface.get_lower_case_cname (null));
+                       
                        var reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_add_interface_static"));
                        reg_call.add_argument (new CCodeIdentifier ("%s_type_id".printf (class_reference.get_lower_case_cname (null))));
                        reg_call.add_argument (new CCodeIdentifier (iface.get_upper_case_cname ("TYPE_")));
index b5bd643b871861f4d2fcb21a08607633b3ba8580..7eb8b718a758bb4a8a3ee11d1dbc2e8644ac7ce5 100644 (file)
@@ -159,6 +159,7 @@ public class Vala.CodeGenerator {
                once.append (new CCodeIdentifier ("G_END_DECLS"));
                once.append (new CCodeNewline ());
                once.append (new CCodeNewline ());
+               once.write_declaration (writer);
                once.write (writer);
                writer.close ();
                
@@ -170,8 +171,10 @@ public class Vala.CodeGenerator {
                writer.write_newline ();
                source_include_directives.write (writer);
                writer.write_newline ();
+               source_type_member_declaration.write_declaration (writer);
                source_type_member_declaration.write (writer);
                writer.write_newline ();
+               source_signal_marshaller_declaration.write_declaration (writer);
                source_signal_marshaller_declaration.write (writer);
                writer.write_newline ();
                source_type_member_definition.write (writer);
similarity index 95%
rename from vala/valatyperegisterfunction.vala
rename to gobject/valatyperegisterfunction.vala
index d8a3044af9a6dce489087ee72c68bc8e5e41af80..7cde82a7fbf2b92636090530bfac94cfa8b88d03 100644 (file)
@@ -68,6 +68,9 @@ public abstract class Vala.TypeRegisterFunction {
                ctypedecl.modifiers = CCodeModifiers.STATIC;
                ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("g_define_type_info", new CCodeConstant ("{ sizeof (%s), (GBaseInitFunc) %s, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s, (GClassFinalizeFunc) NULL, NULL, %s, 0, (GInstanceInitFunc) %s }".printf (get_type_struct_name (), get_base_init_func_name (), get_class_init_func_name (), get_instance_struct_size (), get_instance_init_func_name ()))));
                type_init.add_statement (ctypedecl);
+
+               type_init.add_statement (get_type_interface_init_declaration ());
+
                CCodeFunctionCall reg_call;
                if (!plugin) {
                        reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_register_static"));
@@ -159,6 +162,15 @@ public abstract class Vala.TypeRegisterFunction {
                return "0";
        }
 
+       /**
+        * Returns additional C declarations to setup interfaces.
+        *
+        * @return C declarations
+        */
+       public virtual ref CCodeFragment! get_type_interface_init_declaration () {
+               return new CCodeFragment ();
+       }
+
        /**
         * Returns additional C initialization statements to setup interfaces.
         *
index 73f724be0ae7b532da10953ccbf77222063b570d..b8189e6870057e6e3860cfbea9fc6c225ed04190 100644 (file)
@@ -70,9 +70,6 @@ libvalacore_la_SOURCES = \
        valaclass.c \
        valaclass.h \
        valaclass.vala \
-       valaclassregisterfunction.c \
-       valaclassregisterfunction.h \
-       valaclassregisterfunction.vala \
        valacodecontext.c \
        valacodecontext.h \
        valacodecontext.vala \
@@ -160,9 +157,6 @@ libvalacore_la_SOURCES = \
        valainterface.c \
        valainterface.h \
        valainterface.vala \
-       valainterfaceregisterfunction.c \
-       valainterfaceregisterfunction.h \
-       valainterfaceregisterfunction.vala \
        valainterfacewriter.c \
        valainterfacewriter.h \
        valainterfacewriter.vala \
@@ -313,9 +307,6 @@ libvalacore_la_SOURCES = \
        valatypereference.c \
        valatypereference.h \
        valatypereference.vala \
-       valatyperegisterfunction.c \
-       valatyperegisterfunction.h \
-       valatyperegisterfunction.vala \
        valaunaryexpression.c \
        valaunaryexpression.h \
        valaunaryexpression.vala \
@@ -347,7 +338,6 @@ valainclude_HEADERS = \
        valacatchclause.h \
        valacharacterliteral.h \
        valaclass.h \
-       valaclassregisterfunction.h \
        valacodecontext.h \
        valacodenode.h \
        valacodevisitor.h \
@@ -377,7 +367,6 @@ valainclude_HEADERS = \
        valainstancecast.h \
        valaintegerliteral.h \
        valainterface.h \
-       valainterfaceregisterfunction.h \
        valainterfacewriter.h \
        valainvocationexpression.h \
        valainvokable.h \
@@ -428,7 +417,6 @@ valainclude_HEADERS = \
        valatypeofexpression.h \
        valatypeparameter.h \
        valatypereference.h \
-       valatyperegisterfunction.h \
        valaunaryexpression.h \
        valavariabledeclarator.h \
        valawhilestatement.h \
index 95a71ab6954f9c6cb689d7f1ba2de0ffb650b5b6..ff97db7c55bab908238a45040983e3930acb6752 100644 (file)
@@ -47,7 +47,7 @@ typedef enum {
        VALA_MODIFIER_ABSTRACT = 1 << 0,
        VALA_MODIFIER_OVERRIDE = 1 << 1,
        VALA_MODIFIER_STATIC = 1 << 2,
-       VALA_MODIFIER_VIRTUAL = 1 << 3,
+       VALA_MODIFIER_VIRTUAL = 1 << 3
 } ValaModifier;
 
 int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser);
index 3f111eb41fb939cabec29a6fb29d38dfa79f97d8..24303e3a889f9c72e5c20d3fd3775c587f536432 100644 (file)
@@ -294,11 +294,7 @@ public class Vala.Class : DataType {
                }
                return lower_case_csuffix;
        }
-       
-       private void set_lower_case_csuffix (string! csuffix) {
-               this.lower_case_csuffix = csuffix;
-       }
-       
+
        public override ref string get_lower_case_cname (string infix) {
                if (infix == null) {
                        infix = "";
index 3e57c6b937c1262947baeb0ee690d3555b357e69..09c587aedd4eaaa50ffb0d2b821a6647f9acda5d 100644 (file)
@@ -177,11 +177,7 @@ public class Vala.Struct : DataType {
                }
                return lower_case_csuffix;
        }
-       
-       private void set_lower_case_csuffix (string! csuffix) {
-               this.lower_case_csuffix = csuffix;
-       }
-       
+
        public override ref string get_lower_case_cname (string infix) {
                if (infix == null) {
                        infix = "";
@@ -369,6 +365,7 @@ public class Vala.Struct : DataType {
                                return "g_value_get_pointer";
                        } else {
                                Report.error (source_reference, "The value type `%s` doesn't declare a GValue get function".printf (symbol.get_full_name ()));
+                               return null;
                        }
                } else {
                        return get_value_function;
@@ -381,6 +378,7 @@ public class Vala.Struct : DataType {
                                return "g_value_set_pointer";
                        } else {
                                Report.error (source_reference, "The value type `%s` doesn't declare a GValue set function".printf (symbol.get_full_name ()));
+                               return null;
                        }
                } else {
                        return set_value_function;