[vala/wip/attributes: 118/119] Fix hashmap and gir parser



commit 0b2fd41c5657c4ebb5b3c371a7bf02d63594ba6a
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon Jul 4 12:16:57 2011 +0200

    Fix hashmap and gir parser

 vala/valacodenode.vala  |   10 +++++-----
 vala/valagirparser.vala |   25 +++++++++++++++++++++----
 vala/valaparser.vala    |    2 +-
 3 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 91fab8b..2836daf 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -159,7 +159,7 @@ public abstract class Vala.CodeNode {
 		var a = get_attribute (name);
 		if (value && a == null) {
 			if (attributes == null) {
-				attributes = new HashMap<string, Attribute> ();
+				attributes = new HashMap<string, Attribute> (str_hash, str_equal);
 			}
 			attributes.set (name, new Attribute (name, source_reference));
 		} else if (!value && a != null) {
@@ -265,7 +265,7 @@ public abstract class Vala.CodeNode {
 	public void set_attribute_string (string attribute, string argument, string value, SourceReference? source_reference = null) {
 		Attribute a = null;
 		if (attributes == null) {
-			attributes = new HashMap<string, Attribute> ();
+			attributes = new HashMap<string, Attribute> (str_hash, str_equal);
 		} else {
 			a = attributes.get (attribute);
 		}
@@ -286,7 +286,7 @@ public abstract class Vala.CodeNode {
 	public void set_attribute_integer (string attribute, string argument, int value, SourceReference? source_reference = null) {
 		Attribute a = null;
 		if (attributes == null) {
-			attributes = new HashMap<string, Attribute> ();
+			attributes = new HashMap<string, Attribute> (str_hash, str_equal);
 		} else {
 			a = attributes.get (attribute);
 		}
@@ -308,7 +308,7 @@ public abstract class Vala.CodeNode {
 	public void set_attribute_double (string attribute, string argument, double value, SourceReference? source_reference = null) {
 		Attribute a = null;
 		if (attributes == null) {
-			attributes = new HashMap<string, Attribute> ();
+			attributes = new HashMap<string, Attribute> (str_hash, str_equal);
 		} else {
 			a = attributes.get (attribute);
 		}
@@ -330,7 +330,7 @@ public abstract class Vala.CodeNode {
 	public void set_attribute_bool (string attribute, string argument, bool value, SourceReference? source_reference = null) {
 		Attribute a = null;
 		if (attributes == null) {
-			attributes = new HashMap<string, Attribute> ();
+			attributes = new HashMap<string, Attribute> (str_hash, str_equal);
 		} else {
 			a = attributes.get (attribute);
 		}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 7541ed0..f33a655 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -626,6 +626,22 @@ public class Vala.GirParser : CodeVisitor {
 			return finish_cname;
 		}
 
+		public string get_cheader_filename () {
+			if (metadata.has_argument (ArgumentType.CHEADER_FILENAME)) {
+				return metadata.get_string (ArgumentType.CHEADER_FILENAME);
+			}
+			var cheader_filename = symbol.get_attribute_string ("CCode", "cheader_filename");
+			if (cheader_filename != null) {
+				return cheader_filename;
+			}
+			if (parent.name != null) {
+				return parent.get_cheader_filename ();
+			} else if (symbol.source_reference != null) {
+				return symbol.source_reference.file.get_cinclude_filename ();
+			}
+			return "";
+		}
+
 		public void process (GirParser parser) {
 			if (processed) {
 				return;
@@ -850,10 +866,11 @@ public class Vala.GirParser : CodeVisitor {
 					symbol.set_attribute ("Deprecated", true);
 				}
 
-				// cheader filename
-				var cheader_filename = metadata.get_string (ArgumentType.CHEADER_FILENAME);
-				if (cheader_filename != null) {
-					symbol.set_attribute_string ("CCode", "cheader_filename", cheader_filename);
+				if (parent.symbol is Namespace) {
+					// always write cheader filename for namespace children
+					symbol.set_attribute_string ("CCode", "cheader_filename", get_cheader_filename ());
+				} else if (metadata.has_argument (ArgumentType.CHEADER_FILENAME)) {
+					symbol.set_attribute_string ("CCode", "cheader_filename", metadata.get_string (ArgumentType.CHEADER_FILENAME));
 				}
 			}
 
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 95fa3fe..79e5477 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2110,7 +2110,7 @@ public class Vala.Parser : CodeVisitor {
 		if (current () != TokenType.OPEN_BRACKET) {
 			return null;
 		}
-		var attrs = new HashMap<string, Attribute> ();
+		var attrs = new HashMap<string, Attribute> (str_hash, str_equal);
 		while (accept (TokenType.OPEN_BRACKET)) {
 			do {
 				var begin = get_location ();



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