1 #include "general.h" /* must always come first */
12 #include <libxml/xmlmemory.h>
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15 #include "ctags-utils.h"
17 static kindOption Kinds
[] = {
18 { TRUE
, 'f', "function", "functions"},
19 { TRUE
, 'c', "class", "classes"},
20 { TRUE
, 'm', "method", "methods"},
21 { TRUE
, 'p', "property", "properties"},
22 { TRUE
, 'v', "variable", "global variables"}
26 initialize (const langType language
)
31 parse_function (xmlNode
*node
, const gchar
*parent
)
37 g_assert (node
!= NULL
);
39 name
= (gchar
*)xmlGetProp (node
, (xmlChar
*)"name");
43 tag
= (tagEntryInfo
*)malloc (sizeof (tagEntryInfo
));
44 initTagEntry (tag
, name
);
45 get_file_pos (node
->line
, &tag
->filePosition
, File
.fp
);
46 tag
->lineNumber
= node
->line
;
48 tag
->kindName
= "function";
51 tag
->kindName
= "member";
53 tag
->extensionFields
.scope
[0] = "class";
54 tag
->extensionFields
.scope
[1] = parent
;
57 for (i
= node
->children
; i
; i
= i
->next
)
61 if (strcmp ((const gchar
*)i
->name
, "return-value") == 0)
63 for (k
= i
->children
; k
; k
= k
->next
)
68 tmp
= (const gchar
*)xmlGetProp (k
, (const xmlChar
*)"name");
71 tag
->extensionFields
.returnType
= tmp
;
74 if (strcmp ((const gchar
*)i
->name
, "parameters") == 0)
76 for (k
= i
->children
; k
; k
= k
->next
)
78 /*TODO: const gchar *name;
81 name = (const gchar*)xmlGetProp (node, (const xmlChar*)"name");
84 tmp = g_new (Argument, 1);
85 tmp->name = g_strdup (name);
87 ret->args = g_list_append (ret->args, tmp);*/
94 static void makeTags (xmlNode
*node
, const gchar
*parent
);
97 parse_class (xmlNode
*node
)
104 name
= (gchar
*)xmlGetProp (node
, (const xmlChar
*)"name");
108 tagEntryInfo
*tag
= (tagEntryInfo
*)malloc (sizeof (tagEntryInfo
));
109 initTagEntry (tag
, name
);
110 tag
->isFileScope
= 1;
111 tag
->kindName
= "class";
113 get_file_pos (node
->line
, &tag
->filePosition
, File
.fp
);
114 tag
->lineNumber
= node
->line
;
117 for (i
= node
->children
; i
; i
= i
->next
)
124 makeTags (xmlNode
*node
, const gchar
*parent
)
126 g_assert (node
!= NULL
);
127 g_assert (node
->name
!= NULL
);
129 if (strcmp ((const gchar
*)node
->name
, "text") == 0
130 || strcmp ((const gchar
*)node
->name
, "implements") == 0)
132 if (strcmp ((const gchar
*)node
->name
, "enumeration") == 0
133 || strcmp ((const gchar
*)node
->name
, "union") == 0
134 || strcmp ((const gchar
*)node
->name
, "namespace") == 0
135 || strcmp ((const gchar
*)node
->name
, "class") == 0
136 || strcmp ((const gchar
*)node
->name
, "record") == 0
137 || strcmp ((const gchar
*)node
->name
, "bitfield") == 0
138 || strcmp ((const gchar
*)node
->name
, "interface") == 0)
143 if (strcmp ((const gchar
*)node
->name
, "function") == 0 || strcmp ((const gchar
*)node
->name
, "method") == 0
144 || strcmp ((const gchar
*)node
->name
, "callback") == 0
145 || strcmp ((const gchar
*)node
->name
, "constructor") == 0)
147 parse_function (node
, parent
);
150 if (strcmp ((const gchar
*)node
->name
, "alias") == 0 ||
151 strcmp ((const gchar
*)node
->name
, "constant") == 0 ||
152 strcmp ((const gchar
*)node
->name
, "signal") == 0 ||
153 strcmp ((const gchar
*)node
->name
, "field") == 0 ||
154 strcmp ((const gchar
*)node
->name
, "property") == 0 ||
155 strcmp ((const gchar
*)node
->name
, "member") == 0)
157 gchar
*name
= (gchar
*)xmlGetProp (node
, (const xmlChar
*)"name");
160 tagEntryInfo
*tag
= (tagEntryInfo
*)malloc (sizeof (tagEntryInfo
));
161 initTagEntry (tag
, name
);
162 tag
->isFileScope
= 1;
163 tag
->kindName
= "variable";
165 get_file_pos (node
->line
, &tag
->filePosition
, File
.fp
);
166 tag
->lineNumber
= node
->line
;
168 tag
->kindName
= "member";
170 tag
->extensionFields
.scope
[0] = "class";
171 tag
->extensionFields
.scope
[1] = parent
;
182 xmlDocPtr doc
= xmlParseFile(getInputFileName());
186 g_warning ("could not parse file");
188 root
= xmlDocGetRootElement(doc
);
189 for (i
= root
->children
; i
; i
= i
->next
)
194 if (strcmp ((const char*)i
->name
, "namespace") !=0)
196 for (j
= i
->children
; j
; j
= j
->next
)
203 extern parserDefinition
*
206 static const char *const extensions
[] = { "gir", NULL
};
207 parserDefinition
*const def
= parserNew ("GObject-Introspection");
208 def
->extensions
= extensions
;
211 def
->kindCount
= KIND_COUNT (Kinds
);
212 def
->parser
= findTags
;
213 def
->initialize
= initialize
;