From: Didier 'Ptitjes Date: Sun, 22 Mar 2009 15:34:29 +0000 (+0100) Subject: GIR writer: Generate annotations on all elements X-Git-Tag: 0.7.2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=272f24bfa19ee7be735dd2a5feacc1ea02d111ad;p=thirdparty%2Fvala.git GIR writer: Generate annotations on all elements Signed-off-by: Didier 'Ptitjes --- diff --git a/gobject/valagirwriter.vala b/gobject/valagirwriter.vala index 2f6a1e35b..5918d06c5 100644 --- a/gobject/valagirwriter.vala +++ b/gobject/valagirwriter.vala @@ -114,6 +114,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf ("\n", ns.name); indent++; + write_annotations (ns); + ns.accept_children (this); indent--; @@ -165,6 +167,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf ("\n"); } + write_annotations (cl); + cl.accept_children (this); indent--; @@ -193,6 +197,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (cl); + cl.accept_children (this); indent--; @@ -215,6 +221,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (st); + st.accept_children (this); indent--; @@ -264,6 +272,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf ("\n"); } + write_annotations (iface); + iface.accept_children (this); indent--; @@ -303,6 +313,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (en); + enum_value = 0; en.accept_children (this); @@ -338,7 +350,11 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf ("\n"); + stream.printf (">\n"); + + write_annotations (edomain); + + stream.printf ("\n"); write_indent (); stream.printf ("\n"); indent++; + write_annotations (f); + write_type (f.field_type); indent--; @@ -470,6 +488,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (param); + write_type (param.parameter_type); indent--; @@ -500,6 +520,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (cb); + write_params (cb.get_parameters ()); write_return_type (cb.return_type); @@ -548,6 +570,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (m); + DataType instance_type = null; if (instance) { instance_type = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol); @@ -579,6 +603,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (m); + write_params (m.get_parameters ()); var datatype = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol); @@ -612,6 +638,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (prop); + write_type (prop.property_type); indent--; @@ -629,6 +657,8 @@ public class Vala.GIRWriter : CodeVisitor { stream.printf (">\n"); indent++; + write_annotations (sig); + write_params (sig.get_parameters ()); write_return_type (sig.return_type); @@ -721,6 +751,23 @@ public class Vala.GIRWriter : CodeVisitor { } } + private void write_annotations (CodeNode node) { + foreach (Attribute attr in node.attributes) { + string name = camel_case_to_canonical (attr.name); + foreach (string arg_name in attr.args.get_keys ()) { + var arg = attr.args.get (arg_name); + + string value = literal_expression_to_value_string ((Literal) arg); + + if (value != null) { + write_indent (); + stream.printf ("\n", + name, camel_case_to_canonical (arg_name), value); + } + } + } + } + private string gi_type_name (TypeSymbol type_symbol) { return vala_to_gi_type_name (type_symbol.get_full_name()); } @@ -784,6 +831,10 @@ public class Vala.GIRWriter : CodeVisitor { .replace ("\"", """); } + private string camel_case_to_canonical (string name) { + return Symbol.camel_case_to_lower_case (name).replace ("_", "-"); + } + private bool check_accessibility (Symbol sym) { if (sym.access == SymbolAccessibility.PUBLIC || sym.access == SymbolAccessibility.PROTECTED) {