2014-02-11 05:42:59 -08:00
|
|
|
#include <Eina.h>
|
2014-06-18 03:25:07 -07:00
|
|
|
#include "eo_parser.h"
|
2014-02-11 05:42:59 -08:00
|
|
|
#include "eolian_database.h"
|
|
|
|
|
2014-07-10 04:15:29 -07:00
|
|
|
Eina_List *_classes = NULL;
|
|
|
|
Eina_Hash *_types = NULL;
|
|
|
|
Eina_Hash *_structs = NULL;
|
|
|
|
Eina_Hash *_filenames = NULL;
|
|
|
|
Eina_Hash *_tfilenames = NULL;
|
2014-03-15 23:33:24 -07:00
|
|
|
|
2014-02-16 01:41:38 -08:00
|
|
|
static int _database_init_count = 0;
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2014-04-30 02:03:09 -07:00
|
|
|
static void _type_hash_free_cb(void *data)
|
|
|
|
{
|
|
|
|
Type_Desc *type = data;
|
|
|
|
eina_stringshare_del(type->alias);
|
|
|
|
database_type_del(type->type);
|
|
|
|
free(type);
|
|
|
|
}
|
|
|
|
|
2014-02-16 01:41:38 -08:00
|
|
|
int
|
2014-02-11 05:42:59 -08:00
|
|
|
database_init()
|
|
|
|
{
|
2014-02-16 01:41:38 -08:00
|
|
|
if (_database_init_count > 0) return ++_database_init_count;
|
2014-02-11 05:42:59 -08:00
|
|
|
eina_init();
|
2014-04-30 02:03:09 -07:00
|
|
|
_types = eina_hash_stringshared_new(_type_hash_free_cb);
|
2014-07-08 08:42:33 -07:00
|
|
|
_structs = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del));
|
2014-04-27 00:57:50 -07:00
|
|
|
_filenames = eina_hash_string_small_new(free);
|
2014-06-24 05:45:51 -07:00
|
|
|
_tfilenames = eina_hash_string_small_new(free);
|
2014-02-16 01:41:38 -08:00
|
|
|
return ++_database_init_count;
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
|
|
|
|
2014-02-16 01:41:38 -08:00
|
|
|
int
|
2014-02-11 05:42:59 -08:00
|
|
|
database_shutdown()
|
|
|
|
{
|
2014-02-16 01:41:38 -08:00
|
|
|
if (_database_init_count <= 0)
|
|
|
|
{
|
2014-02-19 04:09:36 -08:00
|
|
|
ERR("Init count not greater than 0 in shutdown.");
|
2014-02-16 01:41:38 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
_database_init_count--;
|
|
|
|
|
|
|
|
if (_database_init_count == 0)
|
|
|
|
{
|
2014-07-09 08:33:07 -07:00
|
|
|
Eolian_Class *class;
|
2014-05-22 07:24:50 -07:00
|
|
|
EINA_LIST_FREE(_classes, class)
|
2014-07-10 04:15:29 -07:00
|
|
|
database_class_del(class);
|
2014-04-30 02:03:09 -07:00
|
|
|
eina_hash_free(_types);
|
2014-07-08 08:42:33 -07:00
|
|
|
eina_hash_free(_structs);
|
2014-04-27 00:03:39 -07:00
|
|
|
eina_hash_free(_filenames);
|
2014-06-24 05:45:51 -07:00
|
|
|
eina_hash_free(_tfilenames);
|
2014-02-16 01:41:38 -08:00
|
|
|
eina_shutdown();
|
|
|
|
}
|
|
|
|
return _database_init_count;
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
|
|
|
|
2014-04-27 00:03:39 -07:00
|
|
|
#define EO_SUFFIX ".eo"
|
2014-06-24 05:45:51 -07:00
|
|
|
#define EOT_SUFFIX ".eot"
|
2014-07-07 06:22:41 -07:00
|
|
|
|
|
|
|
static char *
|
|
|
|
join_path(const char *path, const char *file)
|
|
|
|
{
|
|
|
|
Eina_Strbuf *buf = eina_strbuf_new();
|
2014-07-09 02:19:36 -07:00
|
|
|
char *ret;
|
2014-07-07 06:22:41 -07:00
|
|
|
|
|
|
|
eina_strbuf_append(buf, path);
|
|
|
|
eina_strbuf_append_char(buf, '/');
|
|
|
|
eina_strbuf_append(buf, file);
|
|
|
|
|
2014-07-09 02:19:36 -07:00
|
|
|
ret = eina_strbuf_string_steal(buf);
|
|
|
|
eina_strbuf_free(buf);
|
|
|
|
return ret;
|
2014-07-07 06:22:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_scan_cb(const char *name, const char *path, void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
Eina_Bool is_eo = eina_str_has_suffix(name, EO_SUFFIX);
|
|
|
|
if (!is_eo && !eina_str_has_suffix(name, EOT_SUFFIX)) return;
|
|
|
|
len = strlen(name) - (is_eo ? sizeof(EO_SUFFIX) : sizeof(EOT_SUFFIX)) + 1;
|
|
|
|
eina_hash_add(is_eo ? _filenames : _tfilenames,
|
|
|
|
eina_stringshare_add_length(name, len), join_path(path, name));
|
|
|
|
}
|
2014-06-24 05:45:51 -07:00
|
|
|
|
2014-04-27 00:03:39 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_directory_scan(const char *dir)
|
|
|
|
{
|
|
|
|
if (!dir) return EINA_FALSE;
|
2014-07-07 06:22:41 -07:00
|
|
|
eina_file_dir_list(dir, EINA_TRUE, _scan_cb, NULL);
|
2014-04-27 00:03:39 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-07 08:46:12 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_system_directory_scan()
|
|
|
|
{
|
|
|
|
Eina_Bool ret;
|
|
|
|
Eina_Strbuf *buf = eina_strbuf_new();
|
|
|
|
eina_strbuf_append(buf, eina_prefix_data_get(_eolian_prefix));
|
|
|
|
eina_strbuf_append(buf, "/include");
|
|
|
|
ret = eolian_directory_scan(eina_strbuf_string_get(buf));
|
|
|
|
eina_strbuf_free(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-19 07:56:38 -07:00
|
|
|
static char *
|
|
|
|
_eolian_class_to_filename(const char *filename)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
Eina_Strbuf *strbuf = eina_strbuf_new();
|
|
|
|
eina_strbuf_append(strbuf, filename);
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_replace_all(strbuf, ".", "_");
|
2014-06-19 07:56:38 -07:00
|
|
|
|
|
|
|
ret = eina_strbuf_string_steal(strbuf);
|
|
|
|
eina_strbuf_free(strbuf);
|
|
|
|
|
|
|
|
eina_str_tolower(&ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-24 05:45:51 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_eot_file_parse(const char *filepath)
|
|
|
|
{
|
|
|
|
return eo_parser_database_fill(filepath, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_eo_file_parse(const char *filepath)
|
2014-04-27 00:03:39 -07:00
|
|
|
{
|
|
|
|
const Eina_List *itr;
|
2014-07-09 13:31:03 -07:00
|
|
|
const Eolian_Class *class = eolian_class_find_by_file(filepath);
|
2014-05-06 23:08:30 -07:00
|
|
|
const char *inherit_name;
|
2014-07-09 08:45:41 -07:00
|
|
|
Eolian_Implement *impl;
|
2014-05-22 07:24:50 -07:00
|
|
|
if (!class)
|
2014-04-27 00:03:39 -07:00
|
|
|
{
|
2014-06-24 05:45:51 -07:00
|
|
|
if (!eo_parser_database_fill(filepath, EINA_FALSE)) return EINA_FALSE;
|
2014-05-22 07:24:50 -07:00
|
|
|
class = eolian_class_find_by_file(filepath);
|
|
|
|
if (!class)
|
2014-04-27 00:03:39 -07:00
|
|
|
{
|
|
|
|
ERR("No class for file %s", filepath);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-05-22 07:24:50 -07:00
|
|
|
EINA_LIST_FOREACH(eolian_class_inherits_list_get(class), itr, inherit_name)
|
2014-04-27 00:03:39 -07:00
|
|
|
{
|
2014-05-22 07:24:50 -07:00
|
|
|
if (!eolian_class_find_by_name(inherit_name))
|
2014-04-27 00:03:39 -07:00
|
|
|
{
|
2014-06-19 07:56:38 -07:00
|
|
|
char *filename = _eolian_class_to_filename(inherit_name);
|
2014-05-21 05:34:08 -07:00
|
|
|
filepath = eina_hash_find(_filenames, filename);
|
|
|
|
if (!filepath)
|
|
|
|
{
|
2014-06-02 06:58:35 -07:00
|
|
|
ERR("Unable to find a file for class %s", inherit_name);
|
2014-05-21 05:34:08 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
if (!eolian_eo_file_parse(filepath)) return EINA_FALSE;
|
2014-06-02 06:58:35 -07:00
|
|
|
if (!eolian_class_find_by_name(inherit_name))
|
|
|
|
{
|
|
|
|
ERR("Unable to find class %s", inherit_name);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2014-05-21 05:34:08 -07:00
|
|
|
free(filename);
|
2014-04-27 00:03:39 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-22 07:24:50 -07:00
|
|
|
EINA_LIST_FOREACH(eolian_class_implements_list_get(class), itr, impl)
|
2014-05-06 23:08:30 -07:00
|
|
|
{
|
2014-07-09 13:31:03 -07:00
|
|
|
const Eolian_Class *impl_class;
|
|
|
|
const Eolian_Function *impl_func;
|
2014-05-25 03:53:49 -07:00
|
|
|
Eolian_Function_Type impl_type = EOLIAN_UNRESOLVED;
|
2014-05-29 04:42:16 -07:00
|
|
|
eolian_implement_information_get(impl, &impl_class, &impl_func, &impl_type);
|
|
|
|
if (!impl_func)
|
2014-05-06 23:08:30 -07:00
|
|
|
{
|
2014-05-29 04:42:16 -07:00
|
|
|
ERR("Unable to find function %s", eolian_implement_full_name_get(impl));
|
2014-05-06 23:08:30 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 00:03:39 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-24 05:45:51 -07:00
|
|
|
static Eina_Bool _tfile_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
|
|
|
|
{
|
|
|
|
Eina_Bool *ret = fdata;
|
|
|
|
if (*ret) *ret = eolian_eot_file_parse(data);
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_all_eot_files_parse()
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_TRUE;
|
|
|
|
eina_hash_foreach(_tfilenames, _tfile_parse, &ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-27 06:23:54 -07:00
|
|
|
static Eina_Bool _file_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
|
|
|
|
{
|
|
|
|
Eina_Bool *ret = fdata;
|
|
|
|
if (*ret) *ret = eolian_eo_file_parse(data);
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eolian_all_eo_files_parse()
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_TRUE;
|
|
|
|
eina_hash_foreach(_filenames, _file_parse, &ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|