From 98fae4f8d2d1f375a18aeaf1e0a0c71107fbeba8 Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann@gmx.de>
Date: Tue, 4 Sep 2007 22:26:47 +0200
Subject: [PATCH] Introduce attribute structure for storing custom attributes in symbol nodes.

Signed-off-by: Mathias Hasselmann <mathias.hasselmann@gmx.de>
---
 allocate.c |    1 +
 allocate.h |    1 +
 lib.h      |    7 +++++++
 parse.c    |    4 ++++
 symbol.c   |    9 +++++++++
 symbol.h   |   22 ++++++++++++++++++++++
 6 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/allocate.c b/allocate.c
index 5cc52a9..0492deb 100644
--- a/allocate.c
+++ b/allocate.c
@@ -114,6 +114,7 @@ void show_allocations(struct allocator_struct *x)
 ALLOCATOR(ident, "identifiers");
 ALLOCATOR(token, "tokens");
 ALLOCATOR(context, "contexts");
+ALLOCATOR(attribute, "attribute");
 ALLOCATOR(symbol, "symbols");
 ALLOCATOR(expression, "expressions");
 ALLOCATOR(statement, "statements");
diff --git a/allocate.h b/allocate.h
index 9f1dc8c..77701e8 100644
--- a/allocate.h
+++ b/allocate.h
@@ -65,6 +65,7 @@ extern void show_allocations(struct allocator_struct *);
 DECLARE_ALLOCATOR(ident);
 DECLARE_ALLOCATOR(token);
 DECLARE_ALLOCATOR(context);
+DECLARE_ALLOCATOR(attribute);
 DECLARE_ALLOCATOR(symbol);
 DECLARE_ALLOCATOR(expression);
 DECLARE_ALLOCATOR(statement);
diff --git a/lib.h b/lib.h
index cef4ab8..5fe538f 100644
--- a/lib.h
+++ b/lib.h
@@ -45,6 +45,7 @@ extern int cmdline_include_nr;
 
 struct ident;
 struct token;
+struct attribute;
 struct symbol;
 struct statement;
 struct expression;
@@ -54,6 +55,7 @@ struct instruction;
 struct multijmp;
 struct pseudo;
 
+DECLARE_PTR_LIST(attribute_list, struct attribute);
 DECLARE_PTR_LIST(symbol_list, struct symbol);
 DECLARE_PTR_LIST(statement_list, struct statement);
 DECLARE_PTR_LIST(expression_list, struct expression);
@@ -198,6 +200,11 @@ static inline void concat_instruction_list(struct instruction_list *from, struct
 	concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
 }
 
+static inline void add_attribute (struct attribute_list **list, struct attribute *attr)
+{
+	add_ptr_list(list, attr);
+}
+
 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
 {
 	add_ptr_list(list, sym);
diff --git a/parse.c b/parse.c
index f452042..2219e86 100644
--- a/parse.c
+++ b/parse.c
@@ -1026,6 +1026,10 @@ static void apply_ctype(struct position pos, struct ctype *thistype, struct ctyp
 	concat_ptr_list((struct ptr_list *)thistype->contexts,
 	                (struct ptr_list **)&ctype->contexts);
 
+	/* Atrributes */
+	concat_ptr_list((struct ptr_list *)thistype->attributes,
+	                (struct ptr_list **)&ctype->attributes);
+
 	/* Alignment */
 	if (thistype->alignment & (thistype->alignment-1)) {
 		warning(pos, "I don't like non-power-of-2 alignments");
diff --git a/symbol.c b/symbol.c
index 7539817..7b39b22 100644
--- a/symbol.c
+++ b/symbol.c
@@ -57,6 +57,15 @@ struct context *alloc_context(void)
 	return __alloc_context(0);
 }
 
+struct attribute *alloc_attribute(struct position pos, enum attribute_type type, struct symbol *symbol)
+{
+	struct attribute *attr = __alloc_attribute(0);
+	attr->type = type;
+	attr->pos = pos;
+	attr->symbol = symbol;
+	return attr;
+}
+
 struct symbol *alloc_symbol(struct position pos, int type)
 {
 	struct symbol *sym = __alloc_symbol(0);
diff --git a/symbol.h b/symbol.h
index 4362f9a..63096f8 100644
--- a/symbol.h
+++ b/symbol.h
@@ -78,10 +78,32 @@ extern struct context *alloc_context(void);
 
 DECLARE_PTR_LIST(context_list, struct context);
 
+enum attribute_type {
+	AT_EXPRESSION,
+	AT_TYPEREF
+};
+
+struct attribute {
+	enum attribute_type type:8;
+
+	struct position pos;
+	struct position endpos;
+	struct symbol *symbol;
+
+	union {
+		struct expression *expr;
+		struct symbol *typeref;
+	};
+};
+
+extern struct attribute *alloc_attribute(struct position pos,
+	enum attribute_type type, struct symbol *symbol);
+
 struct ctype {
 	unsigned long modifiers;
 	unsigned long alignment;
 	struct context_list *contexts;
+	struct attribute_list *attributes;
 	unsigned int as;
 	struct symbol *base_type;
 };
-- 
1.5.2.3

