Commit 601e07f6 authored by Massimo Cora's avatar Massimo Cora

symbol-db-engine refactoring. Fixed #564048 - Split symbol-db-engine into

	* plugins/symbol-db/Makefile.am:
	* plugins/symbol-db/plugin.c (symbol_db_activate),
	(on_prefs_package_remove):
	* plugins/symbol-db/plugin.h:
	* plugins/symbol-db/symbol-db-engine-core.c
	(sdb_engine_cache_lookup), (sdb_engine_insert_cache),
	(sdb_engine_clear_caches), (sdb_engine_init_caches),
	(sdb_engine_execute_unknown_sql), (sdb_engine_execute_select_sql),
	(sdb_engine_execute_non_select_sql),
	(sdb_engine_get_statement_by_query_id),
	(sdb_engine_get_dyn_query_node_by_id),
	(sdb_engine_dyn_child_query_node_destroy),
	(sdb_engine_insert_dyn_query_node_by_id),
	(sdb_engine_get_query_parameters_list),
	(sdb_engine_free_cached_queries),
	(sdb_engine_free_cached_dynamic_queries),
	(sdb_engine_disconnect_from_db),
	(sdb_engine_get_tuple_id_by_unique_name),
	(sdb_engine_get_tuple_id_by_unique_name2),
	(sdb_engine_get_tuple_id_by_unique_name3),
	(sdb_engine_get_tuple_id_by_unique_name4),
	(sdb_engine_get_file_defined_id),
	(sdb_engine_udpated_scope_gtree_populate),
	(sdb_engine_populate_db_by_tags), (sdb_engine_ctags_output_thread),
	(sdb_engine_timeout_trigger_signals), (sdb_engine_thread_monitor),
	(sdb_engine_ctags_output_callback_1), (on_scan_files_end_1),
	(sdb_engine_ctags_launcher_create), (sdb_engine_scan_files_1),
	(sdb_engine_init), (sdb_engine_unlink_shared_files),
	(sdb_engine_unref_removed_launchers),
	(sdb_engine_terminate_threads), (sdb_engine_finalize),
	(sdb_engine_class_init), (sdb_engine_get_type),
	(symbol_db_engine_set_ctags_path), (symbol_db_engine_new),
	(sdb_engine_set_defaults_db_parameters),
	(sdb_engine_connect_to_db), (sdb_engine_create_db_tables),
	(symbol_db_engine_db_exists), (symbol_db_engine_file_exists),
	(symbol_db_engine_close_db), (symbol_db_engine_open_db),
	(symbol_db_engine_add_new_workspace),
	(symbol_db_engine_project_exists),
	(symbol_db_engine_add_new_project), (sdb_engine_add_new_language),
	(sdb_engine_add_new_file), (sdb_engine_get_unique_scan_id),
	(symbol_db_engine_add_new_files), (sdb_engine_add_new_sym_type),
	(sdb_engine_add_new_sym_kind), (sdb_engine_add_new_sym_access),
	(sdb_engine_add_new_sym_implementation),
	(sdb_engine_add_new_heritage),
	(sdb_engine_add_new_scope_definition),
	(sdb_engine_add_new_tmp_heritage_scope),
	(sdb_engine_second_pass_update_scope_1),
	(sdb_engine_second_pass_update_scope),
	(sdb_engine_second_pass_update_heritage),
	(sdb_engine_second_pass_do), (sdb_engine_add_new_symbol),
	(sdb_engine_detects_removed_ids), (sdb_engine_update_file),
	(on_scan_update_files_symbols_end),
	(symbol_db_engine_get_sym_type_conversion_hash),
	(symbol_db_engine_fill_type_array),
	(symbol_db_engine_update_files_symbols),
	(symbol_db_engine_update_project_symbols),
	(symbol_db_engine_remove_file), (symbol_db_engine_remove_files),
	(on_scan_update_buffer_end),
	(symbol_db_engine_update_buffer_symbols):
	* plugins/symbol-db/symbol-db-engine-core.h:
	* plugins/symbol-db/symbol-db-engine-queries.c
	(sdb_engine_walk_down_scope_path),
	(sdb_engine_prepare_file_info_sql),
	(sdb_engine_prepare_symbol_info_sql),
	(symbol_db_engine_get_class_parents_by_symbol_id),
	(symbol_db_engine_get_class_parents),
	(symbol_db_engine_get_global_members_filtered),
	(symbol_db_engine_get_scope_members_by_symbol_id_filtered),
	(symbol_db_engine_get_scope_members_by_symbol_id),
	(symbol_db_engine_get_scope_members),
	(symbol_db_engine_get_current_scope),
	(symbol_db_engine_get_file_symbols),
	(symbol_db_engine_get_symbol_info_by_id),
	(symbol_db_engine_find_symbol_by_name_pattern),
	(symbol_db_engine_get_parent_scope_id_by_symbol_id),
	(symbol_db_engine_find_symbol_by_name_pattern_filtered),
	(symbol_db_engine_get_files_for_project):
	* plugins/symbol-db/symbol-db-engine-queries.h:
	* plugins/symbol-db/symbol-db-engine-utils.c
	(symbol_db_glist_compare_func), (symbol_db_gtree_compare_func),
	(symbol_db_engine_is_locked),
	(symbol_db_engine_get_full_local_path),
	(symbol_db_engine_get_file_db_path),
	(symbol_db_engine_get_files_with_zero_symbols):
	* plugins/symbol-db/symbol-db-engine-utils.h:
	* plugins/symbol-db/symbol-db-engine.c:
	* plugins/symbol-db/symbol-db-engine.h:
	* plugins/symbol-db/symbol-db-view-locals.c
	(symbol_db_view_locals_update_list):
	* plugins/symbol-db/symbol-db-view-search.c:
	* plugins/symbol-db/symbol-db-view-search.h:
	* plugins/symbol-db/symbol-db-view.c (on_scan_end),
	(sdb_view_init), (symbol_db_view_open):
	symbol-db-engine refactoring. Fixed #564048 - Split symbol-db-engine into 
	several files.

svn path=/trunk/; revision=4474
parent 8ad753ae
2008-12-20 Massimo Cora' <mcora@svn.gnome.org>
* plugins/symbol-db/Makefile.am:
* plugins/symbol-db/plugin.c (symbol_db_activate),
(on_prefs_package_remove):
* plugins/symbol-db/plugin.h:
* plugins/symbol-db/symbol-db-engine-core.c
(sdb_engine_cache_lookup), (sdb_engine_insert_cache),
(sdb_engine_clear_caches), (sdb_engine_init_caches),
(sdb_engine_execute_unknown_sql), (sdb_engine_execute_select_sql),
(sdb_engine_execute_non_select_sql),
(sdb_engine_get_statement_by_query_id),
(sdb_engine_get_dyn_query_node_by_id),
(sdb_engine_dyn_child_query_node_destroy),
(sdb_engine_insert_dyn_query_node_by_id),
(sdb_engine_get_query_parameters_list),
(sdb_engine_free_cached_queries),
(sdb_engine_free_cached_dynamic_queries),
(sdb_engine_disconnect_from_db),
(sdb_engine_get_tuple_id_by_unique_name),
(sdb_engine_get_tuple_id_by_unique_name2),
(sdb_engine_get_tuple_id_by_unique_name3),
(sdb_engine_get_tuple_id_by_unique_name4),
(sdb_engine_get_file_defined_id),
(sdb_engine_udpated_scope_gtree_populate),
(sdb_engine_populate_db_by_tags), (sdb_engine_ctags_output_thread),
(sdb_engine_timeout_trigger_signals), (sdb_engine_thread_monitor),
(sdb_engine_ctags_output_callback_1), (on_scan_files_end_1),
(sdb_engine_ctags_launcher_create), (sdb_engine_scan_files_1),
(sdb_engine_init), (sdb_engine_unlink_shared_files),
(sdb_engine_unref_removed_launchers),
(sdb_engine_terminate_threads), (sdb_engine_finalize),
(sdb_engine_class_init), (sdb_engine_get_type),
(symbol_db_engine_set_ctags_path), (symbol_db_engine_new),
(sdb_engine_set_defaults_db_parameters),
(sdb_engine_connect_to_db), (sdb_engine_create_db_tables),
(symbol_db_engine_db_exists), (symbol_db_engine_file_exists),
(symbol_db_engine_close_db), (symbol_db_engine_open_db),
(symbol_db_engine_add_new_workspace),
(symbol_db_engine_project_exists),
(symbol_db_engine_add_new_project), (sdb_engine_add_new_language),
(sdb_engine_add_new_file), (sdb_engine_get_unique_scan_id),
(symbol_db_engine_add_new_files), (sdb_engine_add_new_sym_type),
(sdb_engine_add_new_sym_kind), (sdb_engine_add_new_sym_access),
(sdb_engine_add_new_sym_implementation),
(sdb_engine_add_new_heritage),
(sdb_engine_add_new_scope_definition),
(sdb_engine_add_new_tmp_heritage_scope),
(sdb_engine_second_pass_update_scope_1),
(sdb_engine_second_pass_update_scope),
(sdb_engine_second_pass_update_heritage),
(sdb_engine_second_pass_do), (sdb_engine_add_new_symbol),
(sdb_engine_detects_removed_ids), (sdb_engine_update_file),
(on_scan_update_files_symbols_end),
(symbol_db_engine_get_sym_type_conversion_hash),
(symbol_db_engine_fill_type_array),
(symbol_db_engine_update_files_symbols),
(symbol_db_engine_update_project_symbols),
(symbol_db_engine_remove_file), (symbol_db_engine_remove_files),
(on_scan_update_buffer_end),
(symbol_db_engine_update_buffer_symbols):
* plugins/symbol-db/symbol-db-engine-core.h:
* plugins/symbol-db/symbol-db-engine-queries.c
(sdb_engine_walk_down_scope_path),
(sdb_engine_prepare_file_info_sql),
(sdb_engine_prepare_symbol_info_sql),
(symbol_db_engine_get_class_parents_by_symbol_id),
(symbol_db_engine_get_class_parents),
(symbol_db_engine_get_global_members_filtered),
(symbol_db_engine_get_scope_members_by_symbol_id_filtered),
(symbol_db_engine_get_scope_members_by_symbol_id),
(symbol_db_engine_get_scope_members),
(symbol_db_engine_get_current_scope),
(symbol_db_engine_get_file_symbols),
(symbol_db_engine_get_symbol_info_by_id),
(symbol_db_engine_find_symbol_by_name_pattern),
(symbol_db_engine_get_parent_scope_id_by_symbol_id),
(symbol_db_engine_find_symbol_by_name_pattern_filtered),
(symbol_db_engine_get_files_for_project):
* plugins/symbol-db/symbol-db-engine-queries.h:
* plugins/symbol-db/symbol-db-engine-utils.c
(symbol_db_glist_compare_func), (symbol_db_gtree_compare_func),
(symbol_db_engine_is_locked),
(symbol_db_engine_get_full_local_path),
(symbol_db_engine_get_file_db_path),
(symbol_db_engine_get_files_with_zero_symbols):
* plugins/symbol-db/symbol-db-engine-utils.h:
* plugins/symbol-db/symbol-db-engine.c:
* plugins/symbol-db/symbol-db-engine.h:
* plugins/symbol-db/symbol-db-view-locals.c
(symbol_db_view_locals_update_list):
* plugins/symbol-db/symbol-db-view-search.c:
* plugins/symbol-db/symbol-db-view-search.h:
* plugins/symbol-db/symbol-db-view.c (on_scan_end),
(sdb_view_init), (symbol_db_view_open):
symbol-db-engine refactoring. Fixed #564048 - Split symbol-db-engine into
several files.
2008-12-20 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
reviewed by: Sébastien Granjoux <seb.sfo@free.fr>
......@@ -48,8 +48,7 @@ libanjuta_symbol_db_la_SOURCES = plugin.c plugin.h \
readtags.c readtags.h \
symbol-db-engine-iterator.c \
symbol-db-engine-iterator.h \
symbol-db-engine.c \
symbol-db-engine.h symbol-db-view.h \
symbol-db-view.h \
symbol-db-view.c \
symbol-db-view-locals.c \
symbol-db-view-locals.h \
......@@ -59,7 +58,11 @@ libanjuta_symbol_db_la_SOURCES = plugin.c plugin.h \
symbol-db-engine-iterator-node.c \
symbol-db-system.h \
symbol-db-system.c symbol-db-prefs.h \
symbol-db-prefs.c
symbol-db-prefs.c symbol-db-engine-queries.c \
symbol-db-engine-queries.h symbol-db-engine-utils.c \
symbol-db-engine-utils.h symbol-db-engine-priv.h \
symbol-db-engine-core.c symbol-db-engine-core.h \
symbol-db-engine.h
libanjuta_symbol_db_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
......
......@@ -45,7 +45,6 @@
#include "symbol-db-view-locals.h"
#include "symbol-db-view-search.h"
#include "symbol-db-engine.h"
#include "symbol-db-engine-iterator.h"
#include "symbol-db-prefs.h"
#define ICON_FILE "anjuta-symbol-db-plugin-48.png"
......@@ -79,18 +78,6 @@ typedef enum
static unsigned int signals[LAST_SIGNAL] = { 0 };
static gint
g_list_compare (gconstpointer a, gconstpointer b)
{
return strcmp ((const gchar*)a, (const gchar*)b);
}
static gint
gtree_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
{
return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
}
static void
register_stock_icons (AnjutaPlugin *plugin)
{
......@@ -1859,7 +1846,7 @@ symbol_db_activate (AnjutaPlugin *plugin)
/* beign necessary to listen to many scan-end signals, we'll build up a method
* to manage them with just one signal connection
*/
symbol_db->proc_id_tree = g_tree_new_full ((GCompareDataFunc)&gtree_compare_func,
symbol_db->proc_id_tree = g_tree_new_full ((GCompareDataFunc)&symbol_db_gtree_compare_func,
NULL,
NULL,
NULL);
......@@ -2466,7 +2453,7 @@ on_prefs_package_remove (SymbolDBPrefs *sdbp, const gchar *package,
GList *item;
DEBUG_PRINT ("%s", "on_prefs_package_remove");
if ((item = g_list_find_custom (sdb_plugin->session_packages, package,
g_list_compare)) != NULL)
symbol_db_glist_compare_func)) != NULL)
{
sdb_plugin->session_packages = g_list_remove_link (sdb_plugin->session_packages,
item);
......
......@@ -28,7 +28,6 @@
#include <libanjuta/anjuta-plugin.h>
#include <libanjuta/anjuta-launcher.h>
#include "symbol-db-engine.h"
#include "symbol-db-engine-iterator.h"
G_BEGIN_DECLS
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) Massimo Cora' 2007-2008 <maxcvs@email.it>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _SYMBOL_DB_ENGINE_CORE_H_
#define _SYMBOL_DB_ENGINE_CORE_H_
#include <glib-object.h>
#include <glib.h>
#include <libanjuta/interfaces/ianjuta-symbol.h>
#include <libanjuta/anjuta-plugin.h>
#include "symbol-db-engine-iterator.h"
G_BEGIN_DECLS
#define SYMBOL_TYPE_DB_ENGINE (sdb_engine_get_type ())
#define SYMBOL_DB_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngine))
#define SYMBOL_DB_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngineClass))
#define SYMBOL_IS_DB_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYMBOL_TYPE_DB_ENGINE))
#define SYMBOL_IS_DB_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYMBOL_TYPE_DB_ENGINE))
#define SYMBOL_DB_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngineClass))
typedef struct _SymbolDBEngineClass SymbolDBEngineClass;
typedef struct _SymbolDBEngine SymbolDBEngine;
typedef struct _SymbolDBEnginePriv SymbolDBEnginePriv;
struct _SymbolDBEngineClass
{
GObjectClass parent_class;
/* signals */
void (* single_file_scan_end) ();
void (* scan_end) (gint process_id);
void (* symbol_inserted) (gint symbol_id);
void (* symbol_updated) (gint symbol_id);
void (* symbol_scope_updated) (gint symbol_id);
void (* symbol_removed) (gint symbol_id);
};
struct _SymbolDBEngine
{
GObject parent_instance;
SymbolDBEnginePriv *priv;
};
/* WARNING: these must match the ones on libanjuta.idl [AnjutaSymbol::Field] */
typedef enum {
SYMINFO_SIMPLE = 1,
SYMINFO_FILE_PATH = 2,
SYMINFO_IMPLEMENTATION = 4,
SYMINFO_ACCESS = 8,
SYMINFO_KIND = 16,
SYMINFO_TYPE = 32,
SYMINFO_TYPE_NAME = 64,
SYMINFO_LANGUAGE = 128,
SYMINFO_FILE_IGNORE = 256,
SYMINFO_FILE_INCLUDE = 512,
SYMINFO_PROJECT_NAME = 1024,
SYMINFO_WORKSPACE_NAME = 2048
} SymExtraInfo;
GType sdb_engine_get_type (void) G_GNUC_CONST;
/**
* Create a new instance of an engine.
* @param ctags_path is mandatory. No NULL value is accepted.
*/
SymbolDBEngine*
symbol_db_engine_new (const gchar * ctags_path);
/**
* Set a new path for ctags executable.
*/
void
symbol_db_engine_set_ctags_path (SymbolDBEngine *dbe,
const gchar * ctags_path);
/**
* Be sure to check lock status with this function before calling
* something else below. If you call a scanning function while
* dbe is locked there can be some weird behaviours.
*/
gboolean
symbol_db_engine_is_locked (SymbolDBEngine *dbe);
/**
* Open or create a new database at given directory.
* Be sure to give a base_db_path with the ending '/' for directory.
* @param base_db_path directory where .anjuta_sym_db.db will be stored. It can be
* different from project_directory
* E.g: a db on '/tmp/foo/' dir.
* @param prj_directory project directory. It may be different from base_db_path.
* It's mainly used to map files inside the db. Say for example that you want to
* add to a project a file /home/user/project/foo_prj/src/file.c with a project
* directory of /home/user/project/foo_prj/. On db it'll be represented as
* src/file.c. In this way you can move around the project dir without dealing
* with relative paths.
*/
gboolean
symbol_db_engine_open_db (SymbolDBEngine *dbe, const gchar* base_db_path,
const gchar * prj_directory);
/** Disconnect db, gda client and db_connection */
gboolean
symbol_db_engine_close_db (SymbolDBEngine *dbe);
/**
* Check if the database already exists into the prj_directory
*/
gboolean
symbol_db_engine_db_exists (SymbolDBEngine * dbe, const gchar * prj_directory);
/**
* Check if a file is already present [and scanned] in db.
*/
gboolean
symbol_db_engine_file_exists (SymbolDBEngine * dbe, const gchar * abs_file_path);
/** Add a new workspace to an opened database. */
gboolean
symbol_db_engine_add_new_workspace (SymbolDBEngine *dbe, const gchar* workspace);
/**
* Add a new project to workspace to an opened database.
*
* @param workspace Can be NULL. In that case a default workspace will be created,
* and project will depend on that.
* @param project Project name. Must NOT be NULL.
*/
gboolean
symbol_db_engine_add_new_project (SymbolDBEngine *dbe, const gchar* workspace,
const gchar* project);
/**
* Test project existence.
* @return false if project isn't found
*/
gboolean
symbol_db_engine_project_exists (SymbolDBEngine *dbe, /*gchar* workspace, */
const gchar* project_name);
/**
* Add a group of files of a single language to a project. It will perform also
* a symbols scannig/populating of db if scan_symbols is TRUE.
* This function requires an opened db, i.e. calling before
* symbol_db_engine_open_db ().
* @note if some file fails to enter the db the function will return without
* processing the remaining files.
* @param project_name something like 'foo_project', or 'helloworld_project'. Can be NULL,
* for example when you're populating after abort.
* @param project_directory something like the base path '/home/user/projects/foo_project/'
* Be sure not to exchange the db_directory with project_directory! they're different!
* It can be NULL but ONLY if you're doing an 'import_after_abort' scan, i.e.
* files entries have already a connection with the parent project.
* @param files_path requires full path to files on disk. Ctags itself requires that.
* it must be something like "/home/path/to/my/foo/file.xyz". Also it requires
* a language string to represent the file.
* An example of files_path array composition can be:
* "/home/user/foo_project/foo1.c", "/home/user/foo_project/foo2.cpp",
* "/home/user/foo_project/foo3.java".
* @param languages is an array of 'languages'. It must have the same number of
* elments that files_path has. It should be populated like this: "C", "C++",
* "Java"
* This is done to be uniform to the language-manager plugin.
* @param force_scan If FALSE a check on db will be done to see
* whether the file is already present or not.
* @return scan process id if insertion is successful, -1 on error.
*/
gint
symbol_db_engine_add_new_files (SymbolDBEngine *dbe,
const gchar * project_name,
const GPtrArray *files_path,
const GPtrArray *languages,
gboolean force_scan);
/**
* Update symbols of the whole project. It scans all file symbols etc.
* If force is true then update forcely all the files.
*/
gint
symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe, const gchar *project);
/** Remove a file, together with its symbols, from a project. */
gboolean
symbol_db_engine_remove_file (SymbolDBEngine *dbe, const gchar* project,
const gchar* file);
void
symbol_db_engine_remove_files (SymbolDBEngine * dbe, const gchar * project,
const GPtrArray * files);
/**
* Update symbols of saved files.
* @note WARNING: files_path and it's contents will be freed on
* on_scan_update_files_symbols_end () callback.
* @return scan process id if insertion is successful, -1 on 'no files scanned'.
*/
gint
symbol_db_engine_update_files_symbols (SymbolDBEngine *dbe, const gchar *project,
GPtrArray *files_path,
gboolean update_prj_analyse_time);
/**
* Update symbols of a file by a memory-buffer to perform a real-time updating
* of symbols.
* real_files_list: full path on disk to 'real file' to update. e.g.
* /home/foouser/fooproject/src/main.c.
* They'll be freed inside this function when the scan has ended.
* @return scan process id if insertion is successful, -1 on error.
*/
gint
symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar * project,
GPtrArray * real_files_list,
const GPtrArray * text_buffers,
const GPtrArray * buffer_sizes);
G_END_DECLS
#endif /* _SYMBOL_DB_ENGINE_H_ */
This diff is collapsed.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) Massimo Cora' 2007-2008 <maxcvs@email.it>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _SYMBOL_DB_ENGINE_QUERIES_H_
#define _SYMBOL_DB_ENGINE_QUERIES_H_
#include <glib-object.h>
#include <glib.h>
#include "symbol-db-engine.h"
#include "symbol-db-engine-iterator.h"
/**********************
* ITERATABLE QUERIES
**********************/
/**
* Use this function to find symbols names by patterns like '%foo_func%'
* that will return a family of my_foo_func_1, your_foo_func_2 etc
* @name must not be NULL.
* @name must include the optional '%' character to have a wider match, e.g. "foo_func%"
*/
SymbolDBEngineIterator *
symbol_db_engine_find_symbol_by_name_pattern (SymbolDBEngine *dbe,
const gchar *pattern, SymExtraInfo sym_info);
/**
* @param pattern Pattern you want to search for. If NULL it will use '%' and LIKE for query.
* Please provide a pattern with '%' if you also specify a exact_match = FALSE
* @param exact_match Should the pattern be searched for an exact match?
* @param filter_kinds Can be NULL. In that case these filters will not be taken into consideration.
* @param include_kinds Should the filter_kinds (if not null) be applied as inluded or excluded?
* @param global_symbols_search If TRUE only global public function will be searched. If false
* even private or static (for C language) will be searched.
* @param session_projects Should the search, a global search, be filtered by some packages (projects)?
* If yes then provide a GList, if no then pass NULL.
* @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
* @param results_offset Skip results_offset results. -1 If you don't want to use this par.
* @param sym_info Infos about symbols you want to know.
*/
SymbolDBEngineIterator *
symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
const gchar *pattern,
gboolean exact_match,
const GPtrArray *filter_kinds,
gboolean include_kinds,
gboolean global_symbols_search,
GList *session_projects,
gint results_limit,
gint results_offset,
SymExtraInfo sym_info);
/**
* Return an iterator to the data retrieved from database.
* The iterator, if not null, will contain a list of parent classes for the
* given symbol name.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_class_parents (SymbolDBEngine *dbe, const gchar *klass_name,
const GPtrArray *scope_path, SymExtraInfo sym_info);
/**
* Use this function to get parent symbols of a given class.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_class_parents_by_symbol_id (SymbolDBEngine *dbe,
gint child_klass_symbol_id,
SymExtraInfo sym_info);
/**
* Get the scope specified by the line of the file.
* Iterator should contain just one element if the query is successful, no element
* or NULL is returned if function went wrong.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_current_scope (SymbolDBEngine *dbe,
const gchar* full_local_file_path, gulong line,
SymExtraInfo sym_info);
/**
* Use this function to get symbols of a file.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_file_symbols (SymbolDBEngine *dbe,
const gchar *file_path,
SymExtraInfo sym_info);
/**
* Use this function to get global symbols only. I.e. private or file-only scoped symbols
* will NOT be returned.
* @param filter_kinds Can be NULL. In that case we'll return all the kinds of symbols found
* at root level [global level]. A maximum of 5 filter_kinds are admitted.
* @param include_kinds Should we include in the result the filter_kinds or not?
* @param group_them If TRUE then will be issued a 'group by symbol.name' option.
* If FALSE you can have as result more symbols with the same name but different
* symbols id. See for example more namespaces declared on different files.
* @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
* @param results_offset Skip results_offset results. -1 If you don't want to use this par.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_global_members_filtered (SymbolDBEngine *dbe,
const GPtrArray *filter_kinds,
gboolean include_kinds,
gboolean group_them,
gint results_limit,
gint results_offset,
SymExtraInfo sym_info);
/**
* No iterator for now. We need the quickest query possible.
* @param scoped_symbol_id Symbol you want to know the parent of.
* @param db_file db-relative filename path. eg. /src/foo.c
*/
gint
symbol_db_engine_get_parent_scope_id_by_symbol_id (SymbolDBEngine *dbe,
gint scoped_symbol_id,
const gchar* db_file);
/**
* scope_path cannot be NULL.
* scope_path will be something like "scope1_kind", "scope1_name", "scope2_kind",
* "scope2_name", NULL
*/
SymbolDBEngineIterator *
symbol_db_engine_get_scope_members (SymbolDBEngine *dbe,
const GPtrArray* scope_path,
SymExtraInfo sym_info);
/**
* Sometimes it's useful going to query just with ids [and so integers] to have
* a little speed improvement.
* @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
* @param results_offset Skip results_offset results. -1 If you don't want to use this par.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_scope_members_by_symbol_id (SymbolDBEngine *dbe,
gint scope_parent_symbol_id,
gint results_limit,
gint results_offset,
SymExtraInfo sym_info);
/**
* A filtered version of the symbol_db_engine_get_scope_members_by_symbol_id ().
* You can specify which kind of symbols to retrieve, and if include them or exclude.
* Kinds are 'namespace', 'class' etc.
* @param filter_kinds cannot be NULL.
* @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
* @param results_offset Skip results_offset results. -1 If you don't want to use this par.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_scope_members_by_symbol_id_filtered (SymbolDBEngine *dbe,
gint scope_parent_symbol_id,
const GPtrArray *filter_kinds,
gboolean include_kinds,
gint results_limit,
gint results_offset,
SymExtraInfo sym_info);
/**
* Use this function to get infos about a symbol.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_symbol_info_by_id (SymbolDBEngine *dbe,
gint sym_id,
SymExtraInfo sym_info);
/**
* Gets the files of a project.
* @param project_name name of project you want to know the files of.
* It can be NULL. In that case all the files will be returned.
*/
SymbolDBEngineIterator *
symbol_db_engine_get_files_for_project (SymbolDBEngine *dbe,
const gchar *project_name,
SymExtraInfo sym_info);
#endif
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) Massimo Cora' 2007-2008 <maxcvs@email.it>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#include <libanjuta/anjuta-debug.h>
#include "symbol-db-engine-queries.h"
#include "symbol-db-engine-priv.h"
/*
* extern declarations
*/
extern inline const GdaStatement *
sdb_engine_get_statement_by_query_id (SymbolDBEngine * dbe, static_query_type query_id);
extern inline const GdaSet *
sdb_engine_get_query_parameters_list (SymbolDBEngine *dbe, static_query_type query_id);
extern inline const DynChildQueryNode *
sdb_engine_get_dyn_query_node_by_id (SymbolDBEngine *dbe, dyn_query_type query_id,
SymExtraInfo sym_info, gsize other_parameters);
extern inline const DynChildQueryNode *
sdb_engine_insert_dyn_query_node_by_id (SymbolDBEngine *dbe, dyn_query_type query_id,
SymExtraInfo sym_info, gsize other_parameters,
const gchar *sql);
/*
* implementation starts here
*/
gint
symbol_db_glist_compare_func (gconstpointer a, gconstpointer b)
{
return strcmp ((const gchar*)a, (const gchar*)b);
}
gint
symbol_db_gtree_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
{
return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
}
gboolean
symbol_db_engine_is_locked (SymbolDBEngine * dbe)
{
SymbolDBEnginePriv *priv;
g_return_val_if_fail (dbe != NULL, FALSE);
priv = dbe->priv;
return priv->scanning_status;
}
gchar*
symbol_db_engine_get_full_local_path (SymbolDBEngine *dbe, const gchar* file)
{
SymbolDBEnginePriv *priv;
gchar *full_path;
g_return_val_if_fail (dbe != NULL, NULL);
priv = dbe->priv;
full_path = g_strdup_printf ("%s%s", priv->project_directory, file);
return full_path;
}
gchar*
symbol_db_engine_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_file_path)
{
SymbolDBEnginePriv *priv;
gchar *relative_path;
const gchar *tmp;
g_return_val_if_fail (dbe != NULL, NULL);
g_return_val_if_fail (full_local_file_path != NULL, NULL);
priv = dbe->priv;
if (priv->db_directory == NULL)
return NULL;
if (strlen (priv->project_directory) >= strlen (full_local_file_path))
{
return NULL;
}
tmp = full_local_file_path + strlen (priv->project_directory);
relative_path = strdup (tmp);