[vala] Write custom attributes in VAPI files



commit 1df0691e794e45adadadfa766592078a7ea9af80
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Sat Mar 28 12:27:56 2009 +0100

    Write custom attributes in VAPI files
    
    Fixes bug 577063.
    
    Signed-off-by: Didier 'Ptitjes <ptitjes free fr>
---
 vala/valacodewriter.vala |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index f6a56ea..9e72baa 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 ");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]