[gnome-builder/wip/chergert/layout: 92/118] clang: add helper to get file from a translation unit
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout: 92/118] clang: add helper to get file from a translation unit
- Date: Wed, 5 Jul 2017 11:55:47 +0000 (UTC)
commit d1285ff8772036ba59de32a0ab772d50467fb596
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 3 17:05:57 2017 -0700
clang: add helper to get file from a translation unit
This will be used elsewhere, so add a helper for code reuse.
Signed-off-by: Christian Hergert <chergert redhat com>
plugins/clang/ide-clang-translation-unit.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/plugins/clang/ide-clang-translation-unit.c b/plugins/clang/ide-clang-translation-unit.c
index 9a973d0..64d78e0 100644
--- a/plugins/clang/ide-clang-translation-unit.c
+++ b/plugins/clang/ide-clang-translation-unit.c
@@ -83,6 +83,25 @@ code_complete_state_free (gpointer data)
}
}
+static CXFile
+get_file_for_location (IdeClangTranslationUnit *self,
+ IdeSourceLocation *location)
+{
+ g_autofree gchar *filename = NULL;
+ IdeFile *file;
+ GFile *gfile;
+
+ g_assert (IDE_IS_CLANG_TRANSLATION_UNIT (self));
+ g_assert (location != NULL);
+
+ if (!(file = ide_source_location_get_file (location)) ||
+ !(gfile = ide_file_get_file (file)) ||
+ !(filename = g_file_get_path (gfile)))
+ return NULL;
+
+ return clang_getFile (ide_ref_ptr_get (self->native), filename);
+}
+
/**
* ide_clang_translation_unit_get_index:
* @self: A #IdeClangTranslationUnit.
@@ -915,10 +934,7 @@ ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit *self,
line = ide_source_location_get_line (location);
line_offset = ide_source_location_get_line_offset (location);
- if (!(file = ide_source_location_get_file (location)) ||
- !(gfile = ide_file_get_file (file)) ||
- !(filename = g_file_get_path (gfile)) ||
- !(cxfile = clang_getFile (tu, filename)))
+ if (NULL == (cxfile = get_file_for_location (self, location)))
IDE_RETURN (NULL);
cxlocation = clang_getLocation (tu, cxfile, line + 1, line_offset + 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]