[gobject-introspection] Save the line number of a source comment
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Save the line number of a source comment
- Date: Mon, 20 Sep 2010 02:54:20 +0000 (UTC)
commit cb61330eb495786bf8232ebcb51b0d6d9a753ce7
Author: Johan Dahlin <johan gnome org>
Date: Sun Sep 19 11:33:38 2010 -0300
Save the line number of a source comment
giscanner/annotationparser.py | 3 ++-
giscanner/giscannermodule.c | 11 +++++++----
giscanner/scannerlexer.l | 17 +++++++++++++----
giscanner/sourcescanner.c | 10 +++++++++-
giscanner/sourcescanner.h | 10 +++++++++-
5 files changed, 40 insertions(+), 11 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 2aa198e..ea17578 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -139,7 +139,7 @@ class AnnotationParser(object):
self._parse_comment(comment)
return self._blocks
- def _parse_comment(self, comment):
+ def _parse_comment(self, cmt):
# We're looking for gtk-doc comments here, they look like this:
# /**
# * symbol:
@@ -153,6 +153,7 @@ class AnnotationParser(object):
# - signal: GtkWidget::destroy
# - property: GtkWidget:visible
#
+ comment, lineno = cmt
comment = comment.lstrip()
if not comment.startswith(_COMMENT_HEADER):
return
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 2d2e073..b4aae79 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -517,14 +517,17 @@ pygi_source_scanner_get_comments (PyGISourceScanner *self)
GSList *l, *comments;
PyObject *list;
int i = 0;
-
+
comments = gi_source_scanner_get_comments (self->scanner);
list = PyList_New (g_slist_length (comments));
-
+
for (l = comments; l; l = l->next)
{
- PyObject *item = PyString_FromString (l->data);
- PyList_SetItem (list, i++, item);
+ GISourceComment *comment = l->data;
+ PyObject *item = Py_BuildValue ("(ssi)", comment->comment,
+ comment->filename,
+ comment->line);
+ PyList_SET_ITEM (list, i++, item);
Py_INCREF (item);
}
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index ff1ee0f..4fa40f6 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -210,17 +210,21 @@ yywrap (void)
static void
parse_comment (GISourceScanner *scanner)
{
- GString *comment;
+ GString *string;
int c1, c2;
+ GISourceComment *comment;
+ int comment_lineno;
c1 = input();
c2 = input();
- comment = g_string_new ("");
+ string = g_string_new ("");
+
+ comment_lineno = lineno;
while (c2 != EOF && !(c1 == '*' && c2 == '/'))
{
- g_string_append_c (comment, c1);
+ g_string_append_c (string, c1);
if (c1 == '\n')
lineno++;
@@ -230,8 +234,13 @@ parse_comment (GISourceScanner *scanner)
}
+ comment = g_slice_new (GISourceComment);
+ comment->comment = g_string_free (string, FALSE);
+ comment->line = comment_lineno;
+ comment->filename = g_strdup(scanner->current_filename);
+
scanner->comments = g_slist_prepend (scanner->comments,
- g_string_free (comment, FALSE));
+ comment);
}
static int
diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c
index 14e3a3b..e519a94 100644
--- a/giscanner/sourcescanner.c
+++ b/giscanner/sourcescanner.c
@@ -194,6 +194,14 @@ gi_source_scanner_new (void)
return scanner;
}
+static void
+gi_source_comment_free (GISourceComment *comment)
+{
+ g_free (comment->comment);
+ g_free (comment->filename);
+ g_slice_free (GISourceComment, comment);
+}
+
void
gi_source_scanner_free (GISourceScanner *scanner)
{
@@ -202,7 +210,7 @@ gi_source_scanner_free (GISourceScanner *scanner)
g_hash_table_destroy (scanner->typedef_table);
g_hash_table_destroy (scanner->struct_or_union_or_enum_table);
- g_slist_foreach (scanner->comments, (GFunc)g_free, NULL);
+ g_slist_foreach (scanner->comments, (GFunc)gi_source_comment_free, NULL);
g_slist_free (scanner->comments);
g_slist_foreach (scanner->symbols, (GFunc)gi_source_symbol_unref, NULL);
g_slist_free (scanner->symbols);
diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h
index 581b6b1..a7bc176 100644
--- a/giscanner/sourcescanner.h
+++ b/giscanner/sourcescanner.h
@@ -28,6 +28,7 @@
G_BEGIN_DECLS
+typedef struct _GISourceComment GISourceComment;
typedef struct _GISourceScanner GISourceScanner;
typedef struct _GISourceSymbol GISourceSymbol;
typedef struct _GISourceType GISourceType;
@@ -95,13 +96,20 @@ typedef enum
UNARY_LOGICAL_NEGATION
} UnaryOperator;
+struct _GISourceComment
+{
+ char *comment;
+ char *filename;
+ int line;
+};
+
struct _GISourceScanner
{
char *current_filename;
gboolean macro_scan;
GSList *symbols;
GList *filenames;
- GSList *comments;
+ GSList *comments; /* _GIComment */
GHashTable *typedef_table;
GHashTable *struct_or_union_or_enum_table;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]