1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Massimo Cora' 2007 <maxcvs@email.it>
6 * anjuta is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #ifndef _SYMBOL_DB_ENGINE_H_
26 #define _SYMBOL_DB_ENGINE_H_
28 #include <glib-object.h>
30 #include <libanjuta/interfaces/ianjuta-symbol.h>
31 #include <libanjuta/anjuta-plugin.h>
32 #include "symbol-db-engine-iterator.h"
36 #define SYMBOL_TYPE_DB_ENGINE (sdb_engine_get_type ())
37 #define SYMBOL_DB_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngine))
38 #define SYMBOL_DB_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngineClass))
39 #define SYMBOL_IS_DB_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYMBOL_TYPE_DB_ENGINE))
40 #define SYMBOL_IS_DB_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYMBOL_TYPE_DB_ENGINE))
41 #define SYMBOL_DB_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYMBOL_TYPE_DB_ENGINE, SymbolDBEngineClass))
43 typedef struct _SymbolDBEngineClass SymbolDBEngineClass
;
44 typedef struct _SymbolDBEngine SymbolDBEngine
;
45 typedef struct _SymbolDBEnginePriv SymbolDBEnginePriv
;
47 struct _SymbolDBEngineClass
49 GObjectClass parent_class
;
52 void (* single_file_scan_end
) ();
54 void (* symbol_inserted
) (gint symbol_id
);
55 void (* symbol_updated
) (gint symbol_id
);
56 void (* symbol_scope_updated
) (gint symbol_id
); /* never emitted. */
57 void (* symbol_removed
) (gint symbol_id
);
60 struct _SymbolDBEngine
62 GObject parent_instance
;
63 SymbolDBEnginePriv
*priv
;
69 SYMINFO_FILE_PATH
= 1,
70 SYMINFO_IMPLEMENTATION
= 2,
74 SYMINFO_TYPE_NAME
= 32,
75 SYMINFO_LANGUAGE
= 64,
76 SYMINFO_FILE_IGNORE
= 128,
77 SYMINFO_FILE_INCLUDE
= 256,
78 SYMINFO_PROJECT_NAME
= 512,
79 SYMINFO_WORKSPACE_NAME
= 1024
83 GType
sdb_engine_get_type (void) G_GNUC_CONST
;
87 * Create a new instance of an engine.
88 * @param ctags_path is mandatory. No NULL value is accepted.
91 symbol_db_engine_new (const gchar
* ctags_path
);
94 * Set a new path for ctags executable.
97 symbol_db_engine_set_ctags_path (SymbolDBEngine
*dbe
,
98 const gchar
* ctags_path
);
101 * Be sure to check lock status with this function before calling
102 * something else below. If you call a scanning function while
103 * dbe is locked there can be some weird behaviours.
106 symbol_db_engine_is_locked (SymbolDBEngine
*dbe
);
109 * Open or create a new database.
110 * Be sure to give a base_db_path with the ending '/' for directory.
111 * @param base_db_path directory where .anjuta_sym_db.db will be stored. It can be
112 * different from project_directory
113 * E.g: a db on '/tmp/foo/' dir.
114 * @param prj_directory project directory. It may be different from base_db_path.
115 * It's mainly used to map files inside the db. Say for example that you want to
116 * add to a project a file /home/user/project/foo_prj/src/file.c with a project
117 * directory of /home/user/project/foo_prj/. On db it'll be represented as
118 * src/file.c. In this way you can move around the project dir without dealing
119 * with relative paths.
122 symbol_db_engine_open_db (SymbolDBEngine
*dbe
, const gchar
* base_db_path
,
123 const gchar
* prj_directory
);
126 /** Disconnect db, gda client and db_connection */
128 symbol_db_engine_close_db (SymbolDBEngine
*dbe
);
131 * Check if the database already exists into the db_directory
134 symbol_db_engine_db_exists (SymbolDBEngine
* dbe
, const gchar
* db_directory
);
137 * Check if a file is already present [and scanned] in db.
140 symbol_db_engine_file_exists (SymbolDBEngine
* dbe
, const gchar
* abs_file_path
);
142 /** Add a new workspace to an opened database. */
144 symbol_db_engine_add_new_workspace (SymbolDBEngine
*dbe
, const gchar
* workspace
);
147 /** Add a new project to workspace to an opened database.*/
149 symbol_db_engine_add_new_project (SymbolDBEngine
*dbe
, const gchar
* workspace
,
150 const gchar
* project
);
153 * Test project existence.
154 * @return false if project isn't found
157 symbol_db_engine_project_exists (SymbolDBEngine
*dbe
, /*gchar* workspace, */
158 const gchar
* project_name
);
162 * Add a group of files of a single language to a project. It will perform also
163 * a symbols scannig/populating of db if scan_symbols is TRUE.
164 * This function requires an opened db, i.e. calling before
165 * symbol_db_engine_open_db ().
166 * @note if some file fails to enter the db the function will return without
167 * processing the remaining files.
168 * @param project_name something like 'foo_project', or 'helloworld_project'. Can be NULL,
169 * for example when you're populating after abort.
170 * @param project_directory something like the base path '/home/user/projects/foo_project/'
171 * Be sure not to exchange the db_directory with project_directory! they're different!
172 * @param files_path requires full path to files on disk. Ctags itself requires that.
173 * it must be something like "/home/path/to/my/foo/file.xyz". Also it requires
174 * a language string to represent the file.
175 * An example of files_path array composition can be:
176 * "/home/user/foo_project/foo1.c", "/home/user/foo_project/foo2.cpp",
177 * "/home/user/foo_project/foo3.java".
178 * @param languages is an array of 'languages'. It must have the same number of
179 * elments that files_path has. It should be populated like this: "C", "C++",
181 * This is done to be uniform to the language-manager plugin.
182 * @param force_scan If FALSE a check on db will be done to see
183 * whether the file is already present or not.
184 * @return true is insertion is successful.
187 symbol_db_engine_add_new_files (SymbolDBEngine
*dbe
,
188 const gchar
* project_name
,
189 const GPtrArray
*files_path
,
190 const GPtrArray
*languages
,
191 gboolean force_scan
);
194 * Update symbols of the whole project. It scans all file symbols etc.
195 * If force is true then update forcely all the files.
198 symbol_db_engine_update_project_symbols (SymbolDBEngine
*dbe
, const gchar
*project
);
201 /** Remove a file, together with its symbols, from a project. */
203 symbol_db_engine_remove_file (SymbolDBEngine
*dbe
, const gchar
* project
,
207 * Update symbols of saved files.
208 * WARNING: files_path and it's contents will be freed on callback.
211 symbol_db_engine_update_files_symbols (SymbolDBEngine
*dbe
, const gchar
*project
,
212 GPtrArray
*files_path
,
213 gboolean update_prj_analyse_time
);
216 * Update symbols of a file by a memory-buffer to perform a real-time updating
220 symbol_db_engine_update_buffer_symbols (SymbolDBEngine
* dbe
, const gchar
* project
,
221 GPtrArray
* real_files_list
,
222 const GPtrArray
* text_buffers
,
223 const GPtrArray
* buffer_sizes
);
226 * Return full_local_path given a relative-to-db file path.
227 * User must care to free the returned string.
228 * @param db_file Relative path inside project.
231 symbol_db_engine_get_full_local_path (SymbolDBEngine
*dbe
, const gchar
* db_file
);
235 * Return a db-relativ file path. Es. given the full_local_file_path
236 * /home/user/foo_project/src/foo.c returned file should be /src/foo.c.
237 * Return NULL on error.
240 symbol_db_engine_get_file_db_path (SymbolDBEngine
*dbe
, const gchar
* full_local_file_path
);
243 * Hash table that converts from a char like 'class' 'struct' etc to an
244 * IANJUTA_SYMBOL_TYPE
247 symbol_db_engine_get_sym_type_conversion_hash (SymbolDBEngine
*dbe
);
250 * Return a GPtrArray that must be freed from caller.
253 symbol_db_engine_fill_type_array (IAnjutaSymbolType match_types
);
256 * Try to get all the files with zero symbols: these should be the ones
257 * excluded by an abort on population process.
258 * @return A GPtrArray with paths on disk of the files. Must be freed by caller.
259 * @return NULL if no files are found.
262 symbol_db_engine_get_files_with_zero_symbols (SymbolDBEngine
*dbe
);
265 /**********************
267 **********************/
270 * Use this function to find symbols names by patterns like '%foo_func%'
271 * that will return a family of my_foo_func_1, your_foo_func_2 etc
272 * @name must not be NULL.
273 * @name must include the optional '%' character to have a wider match, e.g. "foo_func%"
275 SymbolDBEngineIterator
*
276 symbol_db_engine_find_symbol_by_name_pattern (SymbolDBEngine
*dbe
,
277 const gchar
*pattern
, SymExtraInfo sym_info
);
280 * @param pattern Pattern you want to search for. If NULL it will use '%' and LIKE for query.
281 * Please provide a pattern with '%' if you also specify a exact_match = FALSE
282 * @param exact_match Should the pattern be searched for an exact match?
283 * @param filter_kinds Can be NULL. In that case these filters will not be taken into consideration.
284 * @param include_kinds Should the filter_kinds (if not null) be applied as inluded or excluded?
285 * @param global_symbols_search If TRUE only global public function will be searched. If false
286 * even private or static (for C language) will be searched.
287 * @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
288 * @param results_offset Skip results_offset results. -1 If you don't want to use this par.
289 * @param sym_info Infos about symbols you want to know.
291 SymbolDBEngineIterator
*
292 symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine
*dbe
,
293 const gchar
*pattern
,
294 gboolean exact_match
,
295 const GPtrArray
*filter_kinds
,
296 gboolean include_kinds
,
297 gboolean global_symbols_search
,
300 SymExtraInfo sym_info
);
304 * Return an iterator to the data retrieved from database.
305 * The iterator, if not null, will contain a list of parent classes for the
308 SymbolDBEngineIterator
*
309 symbol_db_engine_get_class_parents (SymbolDBEngine
*dbe
, const gchar
*klass_name
,
310 const GPtrArray
*scope_path
, SymExtraInfo sym_info
);
313 * Use this function to get parent symbols of a given class.
315 SymbolDBEngineIterator
*
316 symbol_db_engine_get_class_parents_by_symbol_id (SymbolDBEngine
*dbe
,
317 gint child_klass_symbol_id
,
318 SymExtraInfo sym_info
);
321 * Return an iterator to the data retrieved from database.
322 * It will be possible to get the scope specified by the line of the file.
324 SymbolDBEngineIterator
*
325 symbol_db_engine_get_current_scope (SymbolDBEngine
*dbe
,
326 const gchar
* filename
, gulong line
,
327 SymExtraInfo sym_info
);
331 * Use this function to get symbols of a file.
333 SymbolDBEngineIterator
*
334 symbol_db_engine_get_file_symbols (SymbolDBEngine
*dbe
,
335 const gchar
*file_path
,
336 SymExtraInfo sym_info
);
339 * Use this function to get global symbols only. I.e. private or file-only scoped symbols
340 * will NOT be returned.
341 * @param filter_kinds Can be NULL. In that case we'll return all the kinds of symbols found
342 * at root level [global level]. A maximum of 5 filter_kinds are admitted.
343 * @param include_kinds Should we include in the result the filter_kinds or not?
344 * @param group_them If TRUE then will be issued a 'group by symbol.name' option.
345 * If FALSE you can have as result more symbols with the same name but different
346 * symbols id. See for example more namespaces declared on different files.
347 * @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
348 * @param results_offset Skip results_offset results. -1 If you don't want to use this par.
350 SymbolDBEngineIterator
*
351 symbol_db_engine_get_global_members_filtered (SymbolDBEngine
*dbe
,
352 const GPtrArray
*filter_kinds
,
353 gboolean include_kinds
,
357 SymExtraInfo sym_info
);
360 * No iterator for now. We need the quickest query possible.
361 * @param scoped_symbol_id Symbol you want to know the parent of.
362 * @param db_file db-relative filename path. eg. /src/foo.c
365 symbol_db_engine_get_parent_scope_id_by_symbol_id (SymbolDBEngine
*dbe
,
366 gint scoped_symbol_id
,
367 const gchar
* db_file
);
369 /** scope_path cannot be NULL.
370 * scope_path will be something like "scope1_kind", "scope1_name", "scope2_kind",
371 * "scope2_name", NULL
373 SymbolDBEngineIterator
*
374 symbol_db_engine_get_scope_members (SymbolDBEngine
*dbe
,
375 const GPtrArray
* scope_path
,
376 SymExtraInfo sym_info
);
379 * Sometimes it's useful going to query just with ids [and so integers] to have
380 * a little speed improvement.
381 * @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
382 * @param results_offset Skip results_offset results. -1 If you don't want to use this par.
384 SymbolDBEngineIterator
*
385 symbol_db_engine_get_scope_members_by_symbol_id (SymbolDBEngine
*dbe
,
386 gint scope_parent_symbol_id
,
389 SymExtraInfo sym_info
);
392 * A filtered version of the symbol_db_engine_get_scope_members_by_symbol_id ().
393 * You can specify which kind of symbols to retrieve, and if include them or exclude.
394 * Kinds are 'namespace', 'class' etc.
395 * @param filter_kinds cannot be NULL.
396 * @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
397 * @param results_offset Skip results_offset results. -1 If you don't want to use this par.
399 SymbolDBEngineIterator
*
400 symbol_db_engine_get_scope_members_by_symbol_id_filtered (SymbolDBEngine
*dbe
,
401 gint scope_parent_symbol_id
,
402 const GPtrArray
*filter_kinds
,
403 gboolean include_kinds
,
406 SymExtraInfo sym_info
);
409 * Use this function to get infos about a symbol.
411 SymbolDBEngineIterator
*
412 symbol_db_engine_get_symbol_info_by_id (SymbolDBEngine
*dbe
,
414 SymExtraInfo sym_info
);
418 #endif /* _SYMBOL_DB_ENGINE_H_ */