[vala/wip/attributes: 1/13] Add a cache structure in code nodes to be used by code generators



commit 7d64ff32046ce5e957c1221965941642fe5e06ad
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Jun 25 16:25:23 2011 +0200

    Add a cache structure in code nodes to be used by code generators

 vala/valacodenode.vala |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index b1fc30e..7badfa9 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -47,6 +47,11 @@ public abstract class Vala.CodeNode {
 	 */
 	public GLib.List<Attribute> attributes;
 
+	/**
+	 * Contains objects for handling attributes in the codegen
+	 */
+	public AttributeCache[] attribute_caches;
+
 	public string type_name {
 		get { return Type.from_instance (this).name (); }
 	}
@@ -69,6 +74,7 @@ public abstract class Vala.CodeNode {
 	private static List<DataType> _empty_type_list;
 
 	static int last_temp_nr = 0;
+	static int next_attribute_hash = 0;
 
 	/**
 	 * Specifies the exceptions that can be thrown by this node or a child node
@@ -152,6 +158,32 @@ public abstract class Vala.CodeNode {
 	}
 
 	/**
+	 * Returns the specified attribute cache.
+	 *
+	 * @param hash hash number
+	 * @return     attribute manager
+	 */
+	public AttributeCache? get_attribute_cache (int hash) {
+		if (hash >= attribute_caches.length) {
+			return null;
+		}
+		return attribute_caches[hash];
+	}
+
+	/**
+	 * Sets the specified attribute cache to this code node.
+	 *
+	 * @param hash    hash number
+	 * @param cache attribute cache
+	 */
+	public void set_attribute_cache (int hash, AttributeCache cache) {
+		if (hash >= attribute_caches.length) {
+			attribute_caches.resize (hash * 2 + 1);
+		}
+		attribute_caches[hash] = cache;
+	}
+
+	/**
 	 * Returns a string that represents this code node.
 	 *
 	 * @return a string representation
@@ -177,4 +209,16 @@ public abstract class Vala.CodeNode {
 	public static string get_temp_name () {
 		return "." + (++last_temp_nr).to_string ();
 	}
+
+	/**
+	 * Returns a new hash number for accessing the attribute caches of code nodes
+	 *
+	 * @return a new hash number
+	 */
+	public static int get_attribute_hash () {
+		return next_attribute_hash++;
+	}
+}
+
+public class Vala.AttributeCache {
 }



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