[gnome-builder] symbols: add symbol kind and flags enumerations



commit 19cb5d01b1858cf4ef57b09a587117826d3e0537
Author: Christian Hergert <christian hergert me>
Date:   Sun Mar 29 13:07:00 2015 -0700

    symbols: add symbol kind and flags enumerations
    
    Clang translation unit support is still mostly just stubs, but this let's
    us plumb some things like icon names in the symbol view.

 libide/clang/ide-clang-translation-unit.c |   65 +++++++++++++++++++++++++++-
 libide/ide-internal.h                     |    3 +
 libide/ide-symbol.c                       |   23 ++++++++++
 libide/ide-symbol.h                       |   24 +++++++++++
 4 files changed, 112 insertions(+), 3 deletions(-)
---
diff --git a/libide/clang/ide-clang-translation-unit.c b/libide/clang/ide-clang-translation-unit.c
index 7db94d2..b23f1f1 100644
--- a/libide/clang/ide-clang-translation-unit.c
+++ b/libide/clang/ide-clang-translation-unit.c
@@ -38,7 +38,6 @@
 #include "ide-unsaved-files.h"
 #include "ide-vcs.h"
 
-
 struct _IdeClangTranslationUnit
 {
   IdeObject          parent_instance;
@@ -716,6 +715,57 @@ ide_clang_translation_unit_code_complete_finish (IdeClangTranslationUnit  *self,
   return g_task_propagate_pointer (task, error);
 }
 
+static IdeSymbolKind
+get_symbol_kind (CXCursor        cursor,
+                 IdeSymbolFlags *flags)
+{
+  enum CXAvailabilityKind availability;
+  IdeSymbolFlags local_flags = 0;
+  IdeSymbolKind kind = 0;
+
+  availability = clang_getCursorAvailability (cursor);
+  if (availability == CXAvailability_Deprecated)
+    local_flags |= IDE_SYMBOL_FLAGS_IS_DEPRECATED;
+
+  switch ((int)clang_getCursorKind (cursor))
+    {
+    case CXCursor_StructDecl:
+      kind = IDE_SYMBOL_STRUCT;
+      break;
+
+    case CXCursor_UnionDecl:
+      kind = IDE_SYMBOL_UNION;
+      break;
+
+    case CXCursor_ClassDecl:
+      kind = IDE_SYMBOL_CLASS;
+      break;
+
+    case CXCursor_FunctionDecl:
+      kind = IDE_SYMBOL_FUNCTION;
+      break;
+
+    case CXCursor_EnumDecl:
+      kind = IDE_SYMBOL_ENUM;
+      break;
+
+    case CXCursor_EnumConstantDecl:
+      kind = IDE_SYMBOL_ENUM_VALUE;
+      break;
+
+    case CXCursor_FieldDecl:
+      kind = IDE_SYMBOL_FIELD;
+      break;
+
+    default:
+      break;
+    }
+
+  *flags = local_flags;
+
+  return kind;
+}
+
 IdeSymbol *
 ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit  *self,
                                           IdeSourceLocation        *location,
@@ -727,6 +777,8 @@ ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit  *self,
   g_autoptr(IdeSourceLocation) declaration = NULL;
   g_autoptr(IdeSourceLocation) definition = NULL;
   g_autoptr(IdeSourceLocation) canonical = NULL;
+  IdeSymbolKind symkind = 0;
+  IdeSymbolFlags symflags = 0;
   IdeProject *project;
   IdeContext *context;
   IdeVcs *vcs;
@@ -777,8 +829,11 @@ ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit  *self,
       definition = create_location (self, project, workpath, tmploc);
     }
 
+  symkind = get_symbol_kind (cursor, &symflags);
+
   cxstr = clang_getCursorDisplayName (cursor);
-  ret = _ide_symbol_new (clang_getCString (cxstr), declaration, definition, canonical);
+  ret = _ide_symbol_new (clang_getCString (cxstr), symkind, symflags,
+                         declaration, definition, canonical);
 
   /*
    * TODO: We should also get information about the defintion of the symbol.
@@ -795,6 +850,8 @@ create_symbol (CXCursor         cursor,
   g_auto(CXString) cxname = { 0 };
   g_autoptr(IdeSourceLocation) srcloc = NULL;
   CXSourceLocation cxloc;
+  IdeSymbolKind symkind;
+  IdeSymbolFlags symflags;
   const gchar *name;
   IdeSymbol *symbol;
   guint line;
@@ -806,7 +863,9 @@ create_symbol (CXCursor         cursor,
   clang_getFileLocation (cxloc, NULL, &line, &line_offset, NULL);
   srcloc = ide_source_location_new (state->file, line-1, line_offset-1, 0);
 
-  symbol = _ide_symbol_new (name, NULL, NULL, srcloc);
+  symkind = get_symbol_kind (cursor, &symflags);
+
+  symbol = _ide_symbol_new (name, symkind, symflags, NULL, NULL, srcloc);
 
   return symbol;
 }
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 60d5e0d..dbc5f1f 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -29,6 +29,7 @@
 #include "ide-types.h"
 #include "ide-source-view.h"
 #include "ide-source-view-mode.h"
+#include "ide-symbol.h"
 
 G_BEGIN_DECLS
 
@@ -98,6 +99,8 @@ void                _ide_source_view_set_count         (IdeSourceView         *s
 void                _ide_source_view_set_modifier      (IdeSourceView         *self,
                                                         gunichar               modifier);
 IdeSymbol          *_ide_symbol_new                    (const gchar           *name,
+                                                        IdeSymbolKind          kind,
+                                                        IdeSymbolFlags         flags,
                                                         IdeSourceLocation     *declaration_location,
                                                         IdeSourceLocation     *definition_location,
                                                         IdeSourceLocation     *canonical_location);
diff --git a/libide/ide-symbol.c b/libide/ide-symbol.c
index 5aff1d9..d36ead6 100644
--- a/libide/ide-symbol.c
+++ b/libide/ide-symbol.c
@@ -25,6 +25,9 @@ struct _IdeSymbol
 {
   volatile gint ref_count;
 
+  IdeSymbolKind     kind;
+  IdeSymbolFlags    flags;
+
   gchar             *name;
   IdeSourceLocation *declaration_location;
   IdeSourceLocation *definition_location;
@@ -35,6 +38,8 @@ G_DEFINE_BOXED_TYPE (IdeSymbol, ide_symbol, ide_symbol_ref, ide_symbol_unref)
 
 IdeSymbol *
 _ide_symbol_new (const gchar       *name,
+                 IdeSymbolKind      kind,
+                 IdeSymbolFlags     flags,
                  IdeSourceLocation *declaration_location,
                  IdeSourceLocation *definition_location,
                  IdeSourceLocation *canonical_location)
@@ -43,6 +48,8 @@ _ide_symbol_new (const gchar       *name,
 
   ret = g_new0 (IdeSymbol, 1);
   ret->ref_count = 1;
+  ret->kind = kind;
+  ret->flags = flags;
   ret->name = g_strdup (name);
 
   if (declaration_location)
@@ -115,6 +122,22 @@ ide_symbol_get_canonical_location (IdeSymbol *self)
   return self->canonical_location;
 }
 
+IdeSymbolKind
+ide_symbol_get_kind (IdeSymbol *self)
+{
+  g_return_val_if_fail (self, 0);
+
+  return self->kind;
+}
+
+IdeSymbolFlags
+ide_symbol_get_flags (IdeSymbol *self)
+{
+  g_return_val_if_fail (self, 0);
+
+  return self->flags;
+}
+
 IdeSymbol *
 ide_symbol_ref (IdeSymbol *self)
 {
diff --git a/libide/ide-symbol.h b/libide/ide-symbol.h
index a024f3c..094ae55 100644
--- a/libide/ide-symbol.h
+++ b/libide/ide-symbol.h
@@ -25,9 +25,33 @@ G_BEGIN_DECLS
 
 #define IDE_TYPE_SYMBOL (ide_symbol_get_type())
 
+typedef enum
+{
+  IDE_SYMBOL_NONE,
+  IDE_SYMBOL_SCALAR,
+  IDE_SYMBOL_CLASS,
+  IDE_SYMBOL_FUNCTION,
+  IDE_SYMBOL_METHOD,
+  IDE_SYMBOL_STRUCT,
+  IDE_SYMBOL_UNION,
+  IDE_SYMBOL_FIELD,
+  IDE_SYMBOL_ENUM,
+  IDE_SYMBOL_ENUM_VALUE,
+} IdeSymbolKind;
+
+typedef enum
+{
+  IDE_SYMBOL_FLAGS_NONE          = 0,
+  IDE_SYMBOL_FLAGS_IS_STATIC     = 1 << 0,
+  IDE_sYMBOL_FLAGS_IS_MEMBER     = 1 << 1,
+  IDE_SYMBOL_FLAGS_IS_DEPRECATED = 1 << 2,
+} IdeSymbolFlags;
+
 GType              ide_symbol_get_type                 (void);
 IdeSymbol         *ide_symbol_ref                      (IdeSymbol *self);
 void               ide_symbol_unref                    (IdeSymbol *self);
+IdeSymbolKind      ide_symbol_get_kind                 (IdeSymbol *self);
+IdeSymbolFlags     ide_symbol_get_flags                (IdeSymbol *self);
 const gchar       *ide_symbol_get_name                 (IdeSymbol *self);
 IdeSourceLocation *ide_symbol_get_canonical_location   (IdeSymbol *self);
 IdeSourceLocation *ide_symbol_get_declaration_location (IdeSymbol *self);


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