[gnome-builder/wip/libide] libide: add ide_diagnostic_get_location()



commit f968d0260de1d790bf1c2f77b17054120eb97690
Author: Christian Hergert <christian hergert me>
Date:   Thu Feb 12 17:29:16 2015 -0800

    libide: add ide_diagnostic_get_location()

 libide/clang/ide-clang-translation-unit.c |    7 ++++++-
 libide/ide-diagnostic.c                   |   17 +++++++++++++++--
 libide/ide-diagnostic.h                   |    9 +++++----
 libide/ide-internal.h                     |    3 ++-
 4 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/libide/clang/ide-clang-translation-unit.c b/libide/clang/ide-clang-translation-unit.c
index be75687..a3d1606 100644
--- a/libide/clang/ide-clang-translation-unit.c
+++ b/libide/clang/ide-clang-translation-unit.c
@@ -151,8 +151,10 @@ create_diagnostic (IdeClangTranslationUnit *self,
   enum CXDiagnosticSeverity cxseverity;
   IdeDiagnosticSeverity severity;
   IdeDiagnostic *diag;
+  IdeSourceLocation *loc;
   g_autoptr(gchar) spelling = NULL;
   CXString cxstr;
+  CXSourceLocation cxloc;
   guint num_ranges;
   guint i;
 
@@ -166,7 +168,10 @@ create_diagnostic (IdeClangTranslationUnit *self,
   spelling = g_strdup (clang_getCString (cxstr));
   clang_disposeString (cxstr);
 
-  diag = _ide_diagnostic_new (severity, spelling);
+  cxloc = clang_getDiagnosticLocation (cxdiag);
+  loc = create_location (self, project, cxloc);
+
+  diag = _ide_diagnostic_new (severity, spelling, loc);
 
   for (i = 0; i < num_ranges; i++)
     {
diff --git a/libide/ide-diagnostic.c b/libide/ide-diagnostic.c
index d3c5868..c2124a8 100644
--- a/libide/ide-diagnostic.c
+++ b/libide/ide-diagnostic.c
@@ -29,6 +29,7 @@ struct _IdeDiagnostic
   volatile gint          ref_count;
   IdeDiagnosticSeverity  severity;
   gchar                 *text;
+  IdeSourceLocation     *location;
   GPtrArray             *ranges;
 };
 
@@ -51,7 +52,9 @@ ide_diagnostic_unref (IdeDiagnostic *self)
 
   if (g_atomic_int_dec_and_test (&self->ref_count))
     {
-      g_free (self->text);
+      g_clear_pointer (&self->location, ide_source_location_unref);
+      g_clear_pointer (&self->text, g_free);
+      g_clear_pointer (&self->ranges, g_ptr_array_unref);
       g_slice_free (IdeDiagnostic, self);
     }
 }
@@ -103,9 +106,18 @@ ide_diagnostic_get_range (IdeDiagnostic *self,
   return NULL;
 }
 
+IdeSourceLocation *
+ide_diagnostic_get_location (IdeDiagnostic *self)
+{
+  g_return_val_if_fail (self, NULL);
+
+  return self->location;
+}
+
 IdeDiagnostic *
 _ide_diagnostic_new (IdeDiagnosticSeverity  severity,
-                     const gchar           *text)
+                     const gchar           *text,
+                     IdeSourceLocation     *location)
 {
   IdeDiagnostic *ret;
 
@@ -113,6 +125,7 @@ _ide_diagnostic_new (IdeDiagnosticSeverity  severity,
   ret->ref_count = 1;
   ret->severity = severity;
   ret->text = g_strdup (text);
+  ret->location = location ? ide_source_location_ref (location) : NULL;
 
   return ret;
 }
diff --git a/libide/ide-diagnostic.h b/libide/ide-diagnostic.h
index f010b77..8c31a2d 100644
--- a/libide/ide-diagnostic.h
+++ b/libide/ide-diagnostic.h
@@ -34,14 +34,15 @@ typedef enum
   IDE_DIAGNOSTIC_FATAL    = 4,
 } IdeDiagnosticSeverity;
 
-GType                  ide_diagnostic_get_type          (void);
-GType                  ide_diagnostic_severity_get_type (void);
-IdeDiagnostic         *ide_diagnostic_ref               (IdeDiagnostic *self);
+IdeSourceLocation     *ide_diagnostic_get_location      (IdeDiagnostic *self);
+guint                  ide_diagnostic_get_num_ranges    (IdeDiagnostic *self);
 IdeSourceRange        *ide_diagnostic_get_range         (IdeDiagnostic *self,
                                                          guint          index);
 IdeDiagnosticSeverity  ide_diagnostic_get_severity      (IdeDiagnostic *self);
 const gchar           *ide_diagnostic_get_text          (IdeDiagnostic *self);
-guint                  ide_diagnostic_get_num_ranges    (IdeDiagnostic *self);
+GType                  ide_diagnostic_get_type          (void);
+IdeDiagnostic         *ide_diagnostic_ref               (IdeDiagnostic *self);
+GType                  ide_diagnostic_severity_get_type (void);
 void                   ide_diagnostic_unref             (IdeDiagnostic *self);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeDiagnostic, ide_diagnostic_unref)
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 715a7e6..9582a93 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -46,7 +46,8 @@ void _ide_diagnostician_remove_provider (IdeDiagnostician      *self,
 IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
 
 IdeDiagnostic *_ide_diagnostic_new        (IdeDiagnosticSeverity  severity,
-                                           const gchar           *text);
+                                           const gchar           *text,
+                                           IdeSourceLocation     *location);
 void           _ide_diagnostic_take_range (IdeDiagnostic         *self,
                                            IdeSourceRange        *range);
 void           _ide_diagnostic_add_range  (IdeDiagnostic         *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]