From d1f768fba349e00af1d30f4b6362f6e641ca2fe1 Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann@gmx.de>
Date: Wed, 5 Sep 2007 21:42:38 +0200
Subject: [PATCH] c2xml: Output argument and expansion nodes for macros.

Signed-off-by: Mathias Hasselmann <mathias.hasselmann@gmx.de>
---
 c2xml.c   |   42 ++++++++++++++++++++++++++++++------------
 parse.dtd |   11 ++++++++---
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/c2xml.c b/c2xml.c
index 210a679..0833b2c 100644
--- a/c2xml.c
+++ b/c2xml.c
@@ -64,13 +64,13 @@ static void newPositionProps(xmlNodePtr node, struct position pos, struct positi
         }
 }
 
-static xmlNodePtr new_sym_node(struct symbol *sym, const char *type, xmlNodePtr parent)
+static xmlNodePtr new_sym_node(struct ident *ident, const char *type,
+			       struct position pos, struct position endpos,
+			       xmlNodePtr parent)
 {
-	const char *ident = NULL;
 	xmlNodePtr node;
 
 	assert(type != NULL);
-	assert(sym != NULL);
 	assert(parent != NULL);
 
 	node = xmlNewChild(parent, NULL, BAD_CAST "symbol", NULL);
@@ -78,16 +78,14 @@ static xmlNodePtr new_sym_node(struct symbol *sym, const char *type, xmlNodePtr
 	newProp(node, "type", type);
 	newIdProp(node, "id", idcount);
 
-	if (sym->ident)
-		ident = show_ident(sym->ident);
 	if (ident)
-		newProp(node, "ident", ident);
+		newProp(node, "ident", show_ident(ident));
 
-	newPositionProps (node, sym->pos, sym->endpos);
+	newPositionProps (node, pos, endpos);
 
 	idcount++;
 
-	return (sym->aux = node);
+	return node;
 }
 
 static inline void examine_members(struct symbol_list *list, xmlNodePtr node)
@@ -270,7 +268,10 @@ static void examine_symbol(struct symbol *sym, xmlNodePtr node)
 	if (sym->ident && sym->ident->reserved)
 		return;
 
-	child = new_sym_node(sym, get_type_name(sym->type), node);
+	child = new_sym_node(sym->ident, get_type_name(sym->type),
+			     sym->pos, sym->endpos, node);
+	sym->aux = child;
+
 	examine_modifiers(sym, child);
 	examine_layout(sym, child);
 	examine_ctype (&sym->ctype, child);
@@ -316,8 +317,10 @@ static struct position *get_expansion_end (struct token *token)
 
 static void examine_macro(struct symbol *sym, xmlNodePtr node)
 {
-	xmlNodePtr child;
 	struct position *pos;
+	struct token *arg;
+	xmlNodePtr child;
+	int i;
 
 	/* this should probably go in the main codebase*/
 	pos = get_expansion_end(sym->expansion);
@@ -326,7 +329,22 @@ static void examine_macro(struct symbol *sym, xmlNodePtr node)
 	else
 		sym->endpos = sym->pos;
 
-	child = new_sym_node(sym, "macro", node);
+	node = new_sym_node(sym->ident, "macro", sym->pos, sym->endpos, node);
+
+	if (sym->arglist) {
+		newProp(node, "has-arguments", "1");
+		arg = sym->arglist->next;
+
+		for (i = 0; i < sym->arglist->count.normal; ++i) {
+			child = new_sym_node (arg->ident, "node", arg->pos, arg->pos, node);
+			xmlNewProp (child, BAD_CAST "base-type", xmlGetProp(node, BAD_CAST "id"));
+		}
+	}
+
+	child = xmlNewChild(node, NULL, BAD_CAST "expression", NULL);
+
+	newProp(child, "type", "string");
+	newProp(child, "value", show_token(sym->expansion));
 }
 
 static void examine_namespace(struct symbol *sym)
@@ -435,7 +453,7 @@ static struct init_keyword attribute_table[] = {
 	{ "element_type",	NS_KEYWORD, .op = &store_typename_attribute_op },
 };
 
-static void initialize_attributes()
+static void initialize_attributes(void)
 {
 	struct symbol *keyword;
 
diff --git a/parse.dtd b/parse.dtd
index f712fda..b4608d2 100644
--- a/parse.dtd
+++ b/parse.dtd
@@ -1,6 +1,6 @@
 <!ELEMENT parse (symbol+) >
 
-<!ELEMENT symbol ((symbol|expression)*) >
+<!ELEMENT symbol ((symbol|expression|type-reference)*) >
 
 <!ATTLIST symbol type (uninitialized|preprocessor|basetype|node|pointer|function|array|struct|union|enum|typedef|typeof|member|bitfield|label|restrict|fouled|keyword|bad|macro) #REQUIRED
 		 id ID #REQUIRED
@@ -49,9 +49,10 @@
 		 force (0|1) #IMPLIED
 		 explicitly-signed (0|1) #IMPLIED
 		 bitwise (0|1) #IMPLIED 
-		 user-type (0|1) #IMPLIED>
+		 user-type (0|1) #IMPLIED
+		 has-arguments (0|1) #IMPLIED>
 
-<!ELEMENT expression EMPTY >
+<!ELEMENT expression EMPTY>
 <!ATTLIST expression type (value|string) #REQUIRED
 		     value CDATA #REQUIRED
 		     file CDATA #REQUIRED
@@ -61,3 +62,7 @@
 		     end-col CDATA #IMPLIED
 		     end-file CDATA #IMPLIED>
 
+<!ELEMENT type-reference EMPTY>
+<!ATTLIST type-reference type CDATA #IMPLIED
+			 type-builtin CDATA #IMPLIED>
+
-- 
1.5.2.3

