From: Didier 'Ptitjes Date: Sat, 28 Mar 2009 11:27:56 +0000 (+0100) Subject: Write custom attributes in VAPI files X-Git-Tag: 0.6.0~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1df0691e794e45adadadfa766592078a7ea9af80;p=thirdparty%2Fvala.git Write custom attributes in VAPI files Fixes bug 577063. Signed-off-by: Didier 'Ptitjes --- diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index f6a56ea9f..9e72baab2 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -83,6 +83,8 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("[CCode (cprefix = \"%s\", lower_case_cprefix = \"%s\")]".printf (ns.get_cprefix (), ns.get_lower_case_cprefix ())); write_newline (); + write_attributes (ns); + write_indent (); write_string ("namespace "); write_identifier (ns.name); @@ -180,6 +182,8 @@ public class Vala.CodeWriter : CodeVisitor { } write_string ("cheader_filename = \"%s\")]".printf (cheaders)); write_newline (); + + write_attributes (cl); write_indent (); write_accessibility (cl); @@ -320,6 +324,8 @@ public class Vala.CodeWriter : CodeVisitor { write_newline (); } + write_attributes (st); + write_indent (); write_accessibility (st); write_string ("struct "); @@ -374,6 +380,8 @@ public class Vala.CodeWriter : CodeVisitor { write_string (")]"); write_newline (); + write_attributes (iface); + write_indent (); write_accessibility (iface); write_string ("interface "); @@ -462,6 +470,8 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("[Flags]"); } + write_attributes (en); + write_indent (); write_accessibility (en); write_string ("enum "); @@ -525,6 +535,8 @@ public class Vala.CodeWriter : CodeVisitor { } write_string ("[CCode (cprefix = \"%s\", cheader_filename = \"%s\")]".printf (edomain.get_cprefix (), cheaders)); + write_attributes (edomain); + write_indent (); write_accessibility (edomain); write_string ("errordomain "); @@ -1637,6 +1649,42 @@ public class Vala.CodeWriter : CodeVisitor { return false; } + private void write_attributes (CodeNode node) { + foreach (Attribute attr in node.attributes) { + if (!filter_attribute (attr)) { + write_indent (); + stream.printf ("[%s", attr.name); + + var keys = attr.args.get_keys (); + if (keys.size != 0) { + stream.printf (" ("); + + string separator = ""; + foreach (string arg_name in keys) { + stream.printf ("%s%s = ", separator, arg_name); + var expr = attr.args.get (arg_name); + expr.accept (this); + separator = ", "; + } + + stream.printf (")"); + } + stream.printf ("]"); + write_newline (); + } + } + } + + private bool filter_attribute (Attribute attr) { + if (attr.name == "CCode" + || attr.name == "Compact" || attr.name == "Immutable" + || attr.name == "SimpleType" || attr.name == "IntegerType" || attr.name == "FloatingType" + || attr.name == "Flags") { + return true; + } + return false; + } + private void write_accessibility (Symbol sym) { if (sym.access == SymbolAccessibility.PUBLIC) { write_string ("public ");