[SYMBOL_LINES] Support for line numbers on Symbols
[gnome.gobject-introspection] / giscanner / sourcescanner.c
index 1902691..14e3a3b 100644 (file)
@@ -6,7 +6,7 @@
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  */
 
 #include "sourcescanner.h"
+#include <string.h>
 
 GISourceSymbol *
-gi_source_symbol_new (GISourceSymbolType type)
+gi_source_symbol_new (GISourceSymbolType type, int line)
 {
   GISourceSymbol *s = g_slice_new0 (GISourceSymbol);
   s->ref_count = 1;
   s->type = type;
+  s->line = line;
   return s;
 }
 
@@ -44,11 +46,14 @@ GISourceSymbol *
 gi_source_symbol_ref (GISourceSymbol * symbol)
 {
   symbol->ref_count++;
+  return symbol;
 }
 
 void
 gi_source_symbol_unref (GISourceSymbol * symbol)
 {
+  if (!symbol)
+    return;
   symbol->ref_count--;
   if (symbol->ref_count == 0)
     {
@@ -56,8 +61,7 @@ gi_source_symbol_unref (GISourceSymbol * symbol)
       if (symbol->base_type)
         ctype_free (symbol->base_type);
       g_free (symbol->const_string);
-      g_slist_foreach (symbol->directives, (GFunc)gi_source_directive_free, NULL);
-      g_slist_free (symbol->directives);
+      g_free (symbol->source_filename);
       g_slice_free (GISourceSymbol, symbol);
     }
 }
@@ -106,6 +110,7 @@ gi_source_type_copy (GISourceType * type)
     result->base_type = gi_source_type_copy (type->base_type);
   for (l = type->child_list; l; l = l->next)
     result->child_list = g_list_append (result->child_list, gi_source_symbol_ref (l->data));
+  result->is_bitfield = type->is_bitfield;
   return result;
 }
 
@@ -159,9 +164,11 @@ gi_source_pointer_new (GISourceType * base_type)
 }
 
 GISourceType *
-gi_source_array_new (void)
+gi_source_array_new (GISourceSymbol *size)
 {
   GISourceType *array = gi_source_type_new (CTYPE_ARRAY);
+  if (size != NULL && size->type == CSYMBOL_TYPE_CONST && size->const_int_set)
+      array->child_list = g_list_append (array->child_list, size);
   return array;
 }
 
@@ -172,28 +179,6 @@ gi_source_function_new (void)
   return func;
 }
 
-GISourceDirective *
-gi_source_directive_new (const gchar *name,
-                        const gchar *value,
-                        GSList *options)
-{
-  GISourceDirective *directive;
-    
-  directive = g_slice_new (GISourceDirective);
-  directive->name = g_strdup (name);
-  directive->value = g_strdup (value);
-  directive->options = options;
-  return directive;
-}
-
-void
-gi_source_directive_free (GISourceDirective *directive)
-{
-  g_free (directive->name);
-  g_free (directive->value);
-  g_slice_free (GISourceDirective, directive);
-}
-
 GISourceScanner *
 gi_source_scanner_new (void)
 {
@@ -202,7 +187,6 @@ gi_source_scanner_new (void)
   scanner = g_slice_new0 (GISourceScanner);
   scanner->typedef_table = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                  g_free, NULL);
-  scanner->directives_map = g_hash_table_new (g_str_hash, g_str_equal);
   scanner->struct_or_union_or_enum_table =
     g_hash_table_new_full (g_str_hash, g_str_equal,
                           g_free, (GDestroyNotify)gi_source_symbol_unref);
@@ -215,10 +199,11 @@ gi_source_scanner_free (GISourceScanner *scanner)
 {
   g_free (scanner->current_filename);
 
-  g_hash_table_destroy (scanner->directives_map);
   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_free (scanner->comments);
   g_slist_foreach (scanner->symbols, (GFunc)gi_source_symbol_unref, NULL);
   g_slist_free (scanner->symbols);
 
@@ -249,6 +234,7 @@ gi_source_scanner_add_symbol (GISourceScanner  *scanner,
   gboolean found_filename = FALSE;
   GList *l;
 
+  g_assert (scanner->current_filename);
   for (l = scanner->filenames; l != NULL; l = l->next)
     {
       if (strcmp (l->data, scanner->current_filename) == 0)
@@ -261,6 +247,11 @@ gi_source_scanner_add_symbol (GISourceScanner  *scanner,
   if (found_filename || scanner->macro_scan)
     scanner->symbols = g_slist_prepend (scanner->symbols,
                                        gi_source_symbol_ref (symbol));
+  /* TODO: Refcounted string here or some other optimization */
+  if (found_filename && symbol->source_filename == NULL)
+    {
+      symbol->source_filename = g_strdup (scanner->current_filename);
+    }
 
   switch (symbol->type)
     {
@@ -286,3 +277,9 @@ gi_source_scanner_get_symbols (GISourceScanner  *scanner)
 {
   return g_slist_reverse (scanner->symbols);
 }
+
+GSList *
+gi_source_scanner_get_comments(GISourceScanner  *scanner)
+{
+  return g_slist_reverse (scanner->comments);
+}