[SYMBOL_LINES] Support for line numbers on Symbols
[gnome.gobject-introspection] / giscanner / giscannermodule.c
index afa4c29..2d2e073 100644 (file)
@@ -22,8 +22,9 @@
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #endif
-#include "sourcescanner.h"
 #include <Python.h>
+#include "sourcescanner.h"
+#include "grealpath.h"
 
 #ifdef _WIN32
 #include <fcntl.h>
@@ -110,6 +111,13 @@ symbol_get_type (PyGISourceSymbol *self,
   return PyInt_FromLong (self->symbol->type);
 }
 
+static PyObject *
+symbol_get_line (PyGISourceSymbol *self,
+                void             *context)
+{
+  return PyInt_FromLong (self->symbol->line);
+}
+
 static PyObject *
 symbol_get_ident (PyGISourceSymbol *self,
                  void            *context)
@@ -135,9 +143,26 @@ static PyObject *
 symbol_get_const_int (PyGISourceSymbol *self,
                      void             *context)
 {
+  if (!self->symbol->const_int_set)
+    {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
   return PyInt_FromLong (self->symbol->const_int);
 }
 
+static PyObject *
+symbol_get_const_double (PyGISourceSymbol *self,
+                         void             *context)
+{
+  if (!self->symbol->const_double_set)
+    {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
+  return PyFloat_FromDouble (self->symbol->const_double);
+}
+
 static PyObject *
 symbol_get_const_string (PyGISourceSymbol *self,
                         void             *context)
@@ -151,6 +176,19 @@ symbol_get_const_string (PyGISourceSymbol *self,
   return PyString_FromString (self->symbol->const_string);
 }
 
+static PyObject *
+symbol_get_source_filename (PyGISourceSymbol *self,
+                            void             *context)
+{
+  if (!self->symbol->source_filename)
+    {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
+
+  return PyString_FromString (self->symbol->source_filename);
+}
+
 static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
   /* int ref_count; */
   { "type", (getter)symbol_get_type, NULL, NULL},
@@ -158,8 +196,12 @@ static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
   { "ident", (getter)symbol_get_ident, NULL, NULL},
   { "base_type", (getter)symbol_get_base_type, NULL, NULL},
   /* gboolean const_int_set; */
-  { "const_int", (getter)symbol_get_const_int, NULL, NULL},  
-  { "const_string", (getter)symbol_get_const_string, NULL, NULL},  
+  { "const_int", (getter)symbol_get_const_int, NULL, NULL},
+  /* gboolean const_double_set; */
+  { "const_double", (getter)symbol_get_const_double, NULL, NULL},
+  { "const_string", (getter)symbol_get_const_string, NULL, NULL},
+  { "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
+  { "line", (getter)symbol_get_line, NULL, NULL},
   { 0 }
 };
 
@@ -256,6 +298,13 @@ type_get_child_list (PyGISourceType *self,
   return list;
 }
 
+static PyObject *
+type_get_is_bitfield (PyGISourceType *self,
+                            void           *context)
+{
+  return PyInt_FromLong (self->type->is_bitfield);
+}
+
 static const PyGetSetDef _PyGISourceType_getsets[] = {
   { "type", (getter)type_get_type, NULL, NULL},
   { "storage_class_specifier", (getter)type_get_storage_class_specifier, NULL, NULL},
@@ -264,6 +313,7 @@ static const PyGetSetDef _PyGISourceType_getsets[] = {
   { "name", (getter)type_get_name, NULL, NULL},
   { "base_type", (getter)type_get_base_type, NULL, NULL},
   { "child_list", (getter)type_get_child_list, NULL, NULL},
+  { "is_bitfield", (getter)type_get_is_bitfield, NULL, NULL},
   { 0 }
 };
 
@@ -294,7 +344,7 @@ pygi_source_scanner_append_filename (PyGISourceScanner *self,
     return NULL;
 
   self->scanner->filenames = g_list_append (self->scanner->filenames,
-                                           g_strdup (filename));
+                                           g_realpath (filename));
   
   Py_INCREF (Py_None);
   return Py_None;
@@ -524,6 +574,9 @@ static int calc_attrs_length(PyObject *attributes, int indent,
   return attr_length + indent + self_indent;
 }
 
+/* Hall of shame, wasted time debugging the code below
+ * 20min - Johan 2009-02-19
+ */
 static PyObject *
 pygi_collect_attributes (PyObject *self,
                         PyObject *args)
@@ -536,8 +589,8 @@ pygi_collect_attributes (PyObject *self,
   GString *attr_value;
   int len;
   
-  if (!PyArg_ParseTuple(args, "sOisi",
-                       &tag_name, &attributes,
+  if (!PyArg_ParseTuple(args, "sO!isi",
+                       &tag_name, &PyList_Type, &attributes,
                        &self_indent, &indent_char,
                        &indent))
     return NULL;
@@ -555,15 +608,28 @@ pygi_collect_attributes (PyObject *self,
 
   first = TRUE;
   attr_value = g_string_new ("");
-
+  
   for (i = 0; i < PyList_Size (attributes); ++i)
     {
       PyObject *tuple;
       char *attr, *value, *escaped;
       
       tuple = PyList_GetItem (attributes, i);
-      g_assert(tuple != NULL);
-      g_assert(PyTuple_Size(tuple) == 2);
+      
+      if (!PyTuple_Check (tuple)) 
+        {
+          PyErr_SetString(PyExc_TypeError,
+                          "attribute item must be a tuple");
+          return NULL;
+        }
+      
+      if (!PyTuple_Size (tuple) == 2)
+        {
+          PyErr_SetString(PyExc_IndexError,
+                          "attribute item must be a tuple of length 2");
+          return NULL;
+        }
+      
       if (PyTuple_GetItem(tuple, 1) == Py_None)
        continue;