diff options
author | Jürg Billeter <j@bitron.ch> | 2007-05-10 11:33:08 +0000 |
---|---|---|
committer | Jürg Billeter <juergbi@src.gnome.org> | 2007-05-10 11:33:08 +0000 |
commit | 0899abe8173717f18a972f6e55b45dcea6eb9071 (patch) | |
tree | bbb7fa8cb2d05b92bd2a44834c606b80a66b8060 | |
parent | 8e156af4e4c740b9c62f59768a2f72870d997fa6 (diff) | |
download | vala-0899abe8173717f18a972f6e55b45dcea6eb9071.tar.gz |
separate declaration output remove comma at end of enum remove unused
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
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | ccode/valaccodeblock.vala | 5 | ||||
-rw-r--r-- | ccode/valaccodedeclaration.vala | 35 | ||||
-rw-r--r-- | ccode/valaccodedeclarator.vala | 10 | ||||
-rw-r--r-- | ccode/valaccodefragment.vala | 8 | ||||
-rw-r--r-- | ccode/valaccodefunctiondeclarator.vala | 6 | ||||
-rw-r--r-- | ccode/valaccodenode.vala | 11 | ||||
-rw-r--r-- | ccode/valaccodeoncesection.vala | 8 | ||||
-rw-r--r-- | ccode/valaccodestruct.vala | 4 | ||||
-rw-r--r-- | ccode/valaccodetypedefinition.vala | 7 | ||||
-rw-r--r-- | ccode/valaccodevariabledeclarator.vala | 23 | ||||
-rw-r--r-- | gobject/Makefile.am | 12 | ||||
-rw-r--r-- | gobject/valaclassregisterfunction.vala (renamed from vala/valaclassregisterfunction.vala) | 19 | ||||
-rw-r--r-- | gobject/valacodegeneratorsourcefile.vala | 3 | ||||
-rw-r--r-- | gobject/valainterfaceregisterfunction.vala (renamed from vala/valainterfaceregisterfunction.vala) | 0 | ||||
-rw-r--r-- | gobject/valatyperegisterfunction.vala (renamed from vala/valatyperegisterfunction.vala) | 12 | ||||
-rw-r--r-- | vala/Makefile.am | 12 | ||||
-rw-r--r-- | vala/parser.y | 2 | ||||
-rw-r--r-- | vala/valaclass.vala | 6 | ||||
-rw-r--r-- | vala/valastruct.vala | 8 |
20 files changed, 170 insertions, 40 deletions
@@ -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 diff --git a/ccode/valaccodeblock.vala b/ccode/valaccodeblock.vala index 3e593ce4e..342109945 100644 --- a/ccode/valaccodeblock.vala +++ b/ccode/valaccodeblock.vala @@ -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 @@ -52,6 +52,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); } writer.write_end_block (); diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala index 8112a0cf4..c0d8605ef 100644 --- a/ccode/valaccodedeclaration.vala +++ b/ccode/valaccodedeclaration.vala @@ -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 (";"); diff --git a/ccode/valaccodedeclarator.vala b/ccode/valaccodedeclarator.vala index 8b63f0bfe..e7cdcbe83 100644 --- a/ccode/valaccodedeclarator.vala +++ b/ccode/valaccodedeclarator.vala @@ -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) { + } } diff --git a/ccode/valaccodefragment.vala b/ccode/valaccodefragment.vala index ef578b0d3..6f2e05bbf 100644 --- a/ccode/valaccodefragment.vala +++ b/ccode/valaccodefragment.vala @@ -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); + } + } } diff --git a/ccode/valaccodefunctiondeclarator.vala b/ccode/valaccodefunctiondeclarator.vala index cc6ef2e51..663456f24 100644 --- a/ccode/valaccodefunctiondeclarator.vala +++ b/ccode/valaccodefunctiondeclarator.vala @@ -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 (") ("); diff --git a/ccode/valaccodenode.vala b/ccode/valaccodenode.vala index e3a28ee2d..77c66d420 100644 --- a/ccode/valaccodenode.vala +++ b/ccode/valaccodenode.vala @@ -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) { + } } diff --git a/ccode/valaccodeoncesection.vala b/ccode/valaccodeoncesection.vala index 831e025b8..5d0ceff34 100644 --- a/ccode/valaccodeoncesection.vala +++ b/ccode/valaccodeoncesection.vala @@ -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 @@ -44,10 +44,16 @@ public class Vala.CCodeOnceSection : CCodeFragment { 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); } writer.write_indent (); writer.write_string ("#endif"); writer.write_newline (); } + + public override void write_declaration (CCodeWriter! writer) { + } } diff --git a/ccode/valaccodestruct.vala b/ccode/valaccodestruct.vala index e11d67ec5..30e6be2d3 100644 --- a/ccode/valaccodestruct.vala +++ b/ccode/valaccodestruct.vala @@ -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 (";"); diff --git a/ccode/valaccodetypedefinition.vala b/ccode/valaccodetypedefinition.vala index 5ef085ba4..dd82a78b9 100644 --- a/ccode/valaccodetypedefinition.vala +++ b/ccode/valaccodetypedefinition.vala @@ -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 (); diff --git a/ccode/valaccodevariabledeclarator.vala b/ccode/valaccodevariabledeclarator.vala index 5a3fc2d43..790b776d7 100644 --- a/ccode/valaccodevariabledeclarator.vala +++ b/ccode/valaccodevariabledeclarator.vala @@ -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 (); } } } diff --git a/gobject/Makefile.am b/gobject/Makefile.am index 2101f5ee0..ff4ea8044 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -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)) diff --git a/vala/valaclassregisterfunction.vala b/gobject/valaclassregisterfunction.vala index 607a04994..29d96ed7f 100644 --- a/vala/valaclassregisterfunction.vala +++ b/gobject/valaclassregisterfunction.vala @@ -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_"))); diff --git a/gobject/valacodegeneratorsourcefile.vala b/gobject/valacodegeneratorsourcefile.vala index b5bd643b8..7eb8b718a 100644 --- a/gobject/valacodegeneratorsourcefile.vala +++ b/gobject/valacodegeneratorsourcefile.vala @@ -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); diff --git a/vala/valainterfaceregisterfunction.vala b/gobject/valainterfaceregisterfunction.vala index 7b9a94d07..7b9a94d07 100644 --- a/vala/valainterfaceregisterfunction.vala +++ b/gobject/valainterfaceregisterfunction.vala diff --git a/vala/valatyperegisterfunction.vala b/gobject/valatyperegisterfunction.vala index d8a3044af..7cde82a7f 100644 --- a/vala/valatyperegisterfunction.vala +++ b/gobject/valatyperegisterfunction.vala @@ -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")); @@ -160,6 +163,15 @@ public abstract class Vala.TypeRegisterFunction { } /** + * 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. * * @return C statements diff --git a/vala/Makefile.am b/vala/Makefile.am index 73f724be0..b8189e687 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -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 \ diff --git a/vala/parser.y b/vala/parser.y index 95a71ab69..ff97db7c5 100644 --- a/vala/parser.y +++ b/vala/parser.y @@ -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); diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 3f111eb41..24303e3a8 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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 = ""; diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 3e57c6b93..09c587aed 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -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; |