From 5c602d5abf4a19c6fb0b60272d209759036c2381 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Fri, 19 May 2006 14:03:34 +0000 Subject: [PATCH] include header file in corresponding source file, generate class macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-05-19 Jürg Billeter * vala/valacodegenerator.vala: include header file in corresponding source file, generate class macros and typedefs * ccode/valaccodeincludedirective.vala * ccode/valaccodemacroreplacement.vala: c macro definition * ccode/valaccodetypedefinition.vala: c typedef * bindings/glib-2.0.vala: correct comment svn path=/trunk/; revision=30 --- vala/ChangeLog | 9 +++++++ vala/bindings/glib-2.0.vala | 2 +- vala/ccode/valaccodeincludedirective.vala | 37 ++++++++++++++++++++++++++++ vala/ccode/valaccodemacroreplacement.vala | 39 ++++++++++++++++++++++++++++++ vala/ccode/valaccodetypedefinition.vala | 40 +++++++++++++++++++++++++++++++ vala/vala/valacodegenerator.vala | 25 +++++++++++++++++++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 vala/ccode/valaccodeincludedirective.vala create mode 100644 vala/ccode/valaccodemacroreplacement.vala create mode 100644 vala/ccode/valaccodetypedefinition.vala diff --git a/vala/ChangeLog b/vala/ChangeLog index 2224b2e..423f5fc 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,12 @@ +2006-05-19 Jürg Billeter + + * vala/valacodegenerator.vala: include header file in corresponding + source file, generate class macros and typedefs + * ccode/valaccodeincludedirective.vala + * ccode/valaccodemacroreplacement.vala: c macro definition + * ccode/valaccodetypedefinition.vala: c typedef + * bindings/glib-2.0.vala: correct comment + 2006-05-18 Jürg Billeter * vala/valacodecontext.vala: add get_source_files method diff --git a/vala/bindings/glib-2.0.vala b/vala/bindings/glib-2.0.vala index d7220e9..f06c771 100644 --- a/vala/bindings/glib-2.0.vala +++ b/vala/bindings/glib-2.0.vala @@ -1,4 +1,4 @@ -/* GLib.vala +/* glib-2.0.vala * * Copyright (C) 2006 Jürg Billeter * diff --git a/vala/ccode/valaccodeincludedirective.vala b/vala/ccode/valaccodeincludedirective.vala new file mode 100644 index 0000000..9e59f3d --- /dev/null +++ b/vala/ccode/valaccodeincludedirective.vala @@ -0,0 +1,37 @@ +/* valaccodeincludedirective.vala + * + * Copyright (C) 2006 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 + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeIncludeDirective : CCodeNode { + public string filename { get; construct; } + + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string ("#include <"); + writer.write_string (filename); + writer.write_string (">"); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodemacroreplacement.vala b/vala/ccode/valaccodemacroreplacement.vala new file mode 100644 index 0000000..afb128f --- /dev/null +++ b/vala/ccode/valaccodemacroreplacement.vala @@ -0,0 +1,39 @@ +/* valaccodemacroreplacement.vala + * + * Copyright (C) 2006 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 + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeMacroReplacement : CCodeNode { + public string name { get; construct; } + public string replacement { get; construct; } + + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string ("#define "); + writer.write_string (name); + writer.write_string (" "); + writer.write_string (replacement); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodetypedefinition.vala b/vala/ccode/valaccodetypedefinition.vala new file mode 100644 index 0000000..8aee708 --- /dev/null +++ b/vala/ccode/valaccodetypedefinition.vala @@ -0,0 +1,40 @@ +/* valaccodetypedefinition.vala + * + * Copyright (C) 2006 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 + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeTypeDefinition : CCodeNode { + public string type_name { get; construct; } + public string typedef_name { get; construct; } + + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string ("typedef "); + writer.write_string (type_name); + writer.write_string (" "); + writer.write_string (typedef_name); + writer.write_string (";"); + writer.write_newline (); + } + } +} diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index 8568bd5..26af22a 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -63,6 +63,8 @@ namespace Vala { if (source_file.comment != null) { header_begin.append (new CCodeComment (text = source_file.comment)); } + + source_include_directives.append (new CCodeIncludeDirective (filename = source_file.get_cheader_filename ())); } public override void visit_end_source_file (SourceFile source_file) { @@ -94,6 +96,29 @@ namespace Vala { instance_struct = new CCodeStruct (name = "_%s".printf (cl.get_cname ())); class_struct = new CCodeStruct (name = "_%sClass".printf (cl.get_cname ())); + + var macro = "(%s_get_type ())".printf (cl.get_lower_case_cname (null)); + header_type_declaration.append (new CCodeMacroReplacement (name = cl.get_upper_case_cname ("TYPE_"), replacement = macro)); + + macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ()); + header_type_declaration.append (new CCodeMacroReplacement (name = "%s(obj)".printf (cl.get_upper_case_cname (null)), replacement = macro)); + + macro = "(G_TYPE_CHECK_CLASS_CAST ((klass), %s, %sClass))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ()); + header_type_declaration.append (new CCodeMacroReplacement (name = "%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), replacement = macro)); + + macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (cl.get_upper_case_cname ("TYPE_")); + header_type_declaration.append (new CCodeMacroReplacement (name = "%s(obj)".printf (cl.get_upper_case_cname ("IS_")), replacement = macro)); + + macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (cl.get_upper_case_cname ("TYPE_")); + header_type_declaration.append (new CCodeMacroReplacement (name = "%s_CLASS(klass)".printf (cl.get_upper_case_cname ("IS_")), replacement = macro)); + + macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (cl.get_upper_case_cname ("TYPE_"), cl.get_cname ()); + header_type_declaration.append (new CCodeMacroReplacement (name = "%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), replacement = macro)); + + + header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (instance_struct.name), typedef_name = cl.get_cname ())); + header_type_declaration.append (new CCodeTypeDefinition (type_name = "struct %s".printf (class_struct.name), typedef_name = "%sClass".printf (cl.get_cname ()))); + instance_struct.add_field (cl.base_class.get_cname (), "parent"); class_struct.add_field ("%sClass".printf (cl.base_class.get_cname ()), "parent"); -- 2.7.4