include header file in corresponding source file, generate class macros
authorJürg Billeter <j@bitron.ch>
Fri, 19 May 2006 14:03:34 +0000 (14:03 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 19 May 2006 14:03:34 +0000 (14:03 +0000)
2006-05-19  Jürg Billeter  <j@bitron.ch>

* 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
vala/bindings/glib-2.0.vala
vala/ccode/valaccodeincludedirective.vala [new file with mode: 0644]
vala/ccode/valaccodemacroreplacement.vala [new file with mode: 0644]
vala/ccode/valaccodetypedefinition.vala [new file with mode: 0644]
vala/vala/valacodegenerator.vala

index 2224b2e..423f5fc 100644 (file)
@@ -1,3 +1,12 @@
+2006-05-19  Jürg Billeter  <j@bitron.ch>
+
+       * 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  <j@bitron.ch>
 
        * vala/valacodecontext.vala: add get_source_files method
index d7220e9..f06c771 100644 (file)
@@ -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 (file)
index 0000000..9e59f3d
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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 (file)
index 0000000..afb128f
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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 (file)
index 0000000..8aee708
--- /dev/null
@@ -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 <j@bitron.ch>
+ */
+
+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 ();
+               }
+       }
+}
index 8568bd5..26af22a 100644 (file)
@@ -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");