2014-06-30 11:32:52 -07:00
|
|
|
|
2014-05-02 15:55:51 -07:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2014-06-30 11:32:52 -07:00
|
|
|
#include <cstddef>
|
2014-05-02 15:55:51 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
#include <Eolian.h>
|
|
|
|
|
|
|
|
#include "eo_types.hh"
|
2014-06-30 11:32:52 -07:00
|
|
|
#include "eo_validate.hh"
|
|
|
|
|
2014-05-02 15:55:51 -07:00
|
|
|
#include "safe_strings.hh"
|
2014-06-30 11:32:52 -07:00
|
|
|
#include "convert_comments.hh"
|
|
|
|
#include "eolian_wrappers.hh"
|
|
|
|
|
|
|
|
namespace eolian_cxx {
|
|
|
|
|
|
|
|
extern efl::eina::log_domain domain;
|
2014-05-02 15:55:51 -07:00
|
|
|
|
|
|
|
static efl::eolian::parameters_container_type
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(Eina_Iterator *parameters,
|
2014-06-30 11:32:52 -07:00
|
|
|
Eolian_Function_Type func_type)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-06-30 11:32:52 -07:00
|
|
|
if (parameters == NULL) return {};
|
|
|
|
assert(func_type != EOLIAN_PROPERTY);
|
|
|
|
|
2014-05-02 15:55:51 -07:00
|
|
|
void *curr;
|
|
|
|
efl::eolian::parameters_container_type list;
|
2014-07-23 00:24:59 -07:00
|
|
|
EINA_ITERATOR_FOREACH(parameters, curr)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-07-09 09:01:19 -07:00
|
|
|
const Eolian_Function_Parameter *id =
|
|
|
|
(static_cast<const Eolian_Function_Parameter*>(curr));
|
2014-06-30 11:32:52 -07:00
|
|
|
list.push_back
|
|
|
|
({
|
2014-07-09 13:02:41 -07:00
|
|
|
parameter_type(*id, func_type),
|
|
|
|
parameter_name(*id)
|
2014-06-30 11:32:52 -07:00
|
|
|
});
|
2014-05-02 15:55:51 -07:00
|
|
|
}
|
2014-07-23 00:24:59 -07:00
|
|
|
eina_iterator_free(parameters);
|
2014-05-02 15:55:51 -07:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-06-30 11:32:52 -07:00
|
|
|
static efl::eolian::parameters_container_type
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(Eolian_Function const& func, getter_t func_type)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
return _convert_eolian_parameters
|
2014-07-23 06:17:19 -07:00
|
|
|
(::eolian_function_parameters_get(&func), func_type.value);
|
2014-06-30 11:32:52 -07:00
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
|
2014-06-30 11:32:52 -07:00
|
|
|
static efl::eolian::parameters_container_type
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(Eina_Iterator *parameters, getter_t func_type)
|
2014-06-30 11:32:52 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
return _convert_eolian_parameters(parameters, func_type.value);
|
2014-06-30 11:32:52 -07:00
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
|
2014-06-30 11:32:52 -07:00
|
|
|
static efl::eolian::parameters_container_type
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(Eina_Iterator *parameters, setter_t func_type)
|
2014-06-30 11:32:52 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
return _convert_eolian_parameters(parameters, func_type.value);
|
2014-06-30 11:32:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static efl::eolian::parameters_container_type
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(Eolian_Function const& func)
|
2014-06-30 11:32:52 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
assert(function_op_type(func) != EOLIAN_PROPERTY);
|
|
|
|
return _convert_eolian_parameters
|
|
|
|
(::eolian_function_parameters_get(&func), function_op_type(func));
|
2014-06-30 11:32:52 -07:00
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
|
2014-09-12 12:50:09 -07:00
|
|
|
static efl::eolian::eo_function
|
|
|
|
_convert_property_set_to_function(Eolian_Class const& klass,
|
|
|
|
Eolian_Function const& prop_)
|
2014-06-30 11:32:52 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
efl::eolian::eo_function set_ =
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-09-12 12:50:09 -07:00
|
|
|
efl::eolian::eo_function::regular_,
|
|
|
|
function_name(prop_) + "_set",
|
2014-09-25 12:09:40 -07:00
|
|
|
function_impl(prop_) + "_set",
|
2014-09-12 12:50:09 -07:00
|
|
|
function_return_type(prop_, eolian_cxx::setter),
|
|
|
|
_convert_eolian_parameters(::eolian_function_parameters_get(&prop_),
|
|
|
|
eolian_cxx::setter),
|
|
|
|
convert_comments_function(klass, prop_, eolian_cxx::setter)
|
|
|
|
};
|
|
|
|
efl::eolian::parameters_container_type keys =
|
|
|
|
_convert_eolian_parameters(::eolian_property_keys_get(&prop_),
|
|
|
|
eolian_cxx::setter);
|
|
|
|
if (!keys.empty())
|
|
|
|
{
|
|
|
|
keys.reserve(keys.size() + set_.params.size());
|
|
|
|
keys.insert(keys.end(), set_.params.begin(),
|
|
|
|
set_.params.end());
|
|
|
|
set_.params = keys;
|
|
|
|
}
|
|
|
|
return set_;
|
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
|
2014-09-12 12:50:09 -07:00
|
|
|
static efl::eolian::eo_function
|
|
|
|
_convert_property_get_to_function(Eolian_Class const& klass,
|
|
|
|
Eolian_Function const& prop_)
|
|
|
|
{
|
|
|
|
efl::eolian::eo_function get_ =
|
|
|
|
{
|
|
|
|
efl::eolian::eo_function::regular_,
|
|
|
|
function_name(prop_) + "_get",
|
2014-09-25 12:09:40 -07:00
|
|
|
function_impl(prop_) + "_get",
|
2014-09-12 12:50:09 -07:00
|
|
|
function_return_type(prop_, eolian_cxx::getter),
|
|
|
|
_convert_eolian_parameters(prop_, eolian_cxx::getter),
|
|
|
|
convert_comments_function(klass, prop_, eolian_cxx::getter)
|
|
|
|
};
|
2014-06-30 11:32:52 -07:00
|
|
|
|
2014-09-12 12:50:09 -07:00
|
|
|
// if the getter has a single parameter and a void return
|
|
|
|
// it is transformed into a getter with no parameters
|
|
|
|
// that actually returns what would be the first argument.
|
|
|
|
if (get_.params.size() == 1 && efl::eolian::type_is_void(get_.ret) &&
|
|
|
|
!function_return_is_explicit_void(prop_, eolian_cxx::getter))
|
|
|
|
{
|
|
|
|
get_.ret = get_.params[0].type;
|
|
|
|
get_.params.clear();
|
|
|
|
}
|
|
|
|
else // otherwise just create the described getter
|
|
|
|
{
|
|
|
|
std::transform
|
|
|
|
(get_.params.begin(), get_.params.end(), get_.params.begin(),
|
|
|
|
[](efl::eolian::eo_parameter const& param)
|
|
|
|
{
|
|
|
|
efl::eolian::eolian_type getter_param_type =
|
|
|
|
type_to_native(param.type);
|
|
|
|
getter_param_type.native += "*";
|
|
|
|
return efl::eolian::eo_parameter
|
|
|
|
{ { getter_param_type }, param.name };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
efl::eolian::parameters_container_type keys =
|
|
|
|
_convert_eolian_parameters(::eolian_property_keys_get(&prop_),
|
|
|
|
eolian_cxx::getter);
|
|
|
|
if (!keys.empty())
|
|
|
|
{
|
|
|
|
keys.reserve(keys.size() + get_.params.size());
|
|
|
|
keys.insert(keys.end(), get_.params.begin(),
|
|
|
|
get_.params.end());
|
|
|
|
get_.params = keys;
|
2014-05-02 15:55:51 -07:00
|
|
|
}
|
2014-09-12 12:50:09 -07:00
|
|
|
return get_;
|
2014-05-02 15:55:51 -07:00
|
|
|
}
|
|
|
|
|
2014-09-12 12:50:09 -07:00
|
|
|
static std::string
|
|
|
|
_convert_class_name(std::string const& name)
|
2014-07-16 16:17:10 -07:00
|
|
|
{
|
|
|
|
return (name == "eo_base" || name == "eo::base" || name == "")
|
|
|
|
? "efl::eo::base"
|
|
|
|
: name;
|
|
|
|
}
|
|
|
|
|
2014-05-02 15:55:51 -07:00
|
|
|
void
|
2014-07-09 11:55:24 -07:00
|
|
|
convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klass)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-07-23 00:24:59 -07:00
|
|
|
Eina_Iterator *inheritances =
|
2014-07-23 06:13:21 -07:00
|
|
|
::eolian_class_inherits_get(&klass);
|
2014-05-02 15:55:51 -07:00
|
|
|
void *curr;
|
|
|
|
|
2014-07-23 00:24:59 -07:00
|
|
|
if (!eina_iterator_next(inheritances, &curr) || !curr)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
|
|
|
cls.parent = "efl::eo::base";
|
2014-07-23 00:24:59 -07:00
|
|
|
eina_iterator_free(inheritances);
|
2014-05-02 15:55:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-16 16:17:10 -07:00
|
|
|
// First element is the parent
|
2014-07-23 00:24:59 -07:00
|
|
|
const char *ptr = static_cast<const char*>(curr);
|
2014-09-12 12:50:09 -07:00
|
|
|
cls.parent = _convert_class_name(class_format_cxx(safe_lower(ptr)));
|
2014-06-30 11:32:52 -07:00
|
|
|
|
2014-07-23 00:24:59 -07:00
|
|
|
EINA_ITERATOR_FOREACH(inheritances, curr)
|
2014-07-16 16:17:10 -07:00
|
|
|
{
|
|
|
|
std::string extension = safe_lower(static_cast<const char*>(curr));
|
2014-09-12 12:50:09 -07:00
|
|
|
cls.extensions.push_back(_convert_class_name(class_format_cxx(extension)));
|
2014-07-16 16:17:10 -07:00
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
}
|
2014-07-23 00:24:59 -07:00
|
|
|
eina_iterator_free(inheritances);
|
2014-05-02 15:55:51 -07:00
|
|
|
}
|
|
|
|
|
2014-06-30 11:32:52 -07:00
|
|
|
void
|
2014-07-09 11:55:24 -07:00
|
|
|
convert_eolian_events(efl::eolian::eo_class& cls, Eolian_Class const& klass)
|
2014-06-30 11:32:52 -07:00
|
|
|
{
|
|
|
|
efl::eolian::events_container_type events = event_list(klass);
|
|
|
|
cls.events.reserve(cls.events.size() + events.size());
|
|
|
|
cls.events.insert(cls.events.end(), events.begin(), events.end());
|
|
|
|
}
|
2014-05-02 15:55:51 -07:00
|
|
|
|
|
|
|
efl::eolian::eo_class
|
2014-07-09 11:55:24 -07:00
|
|
|
convert_eolian_class_new(Eolian_Class const& klass)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-06-30 11:32:52 -07:00
|
|
|
efl::eolian::eo_class cls;
|
|
|
|
cls.type = class_type(klass);
|
2014-09-12 12:50:09 -07:00
|
|
|
cls.name = class_name(klass);
|
2014-07-01 02:55:45 -07:00
|
|
|
cls.name_space = class_namespace_full(klass);
|
2014-06-30 11:32:52 -07:00
|
|
|
cls.eo_name = class_eo_name(klass);
|
|
|
|
cls.comment = convert_comments_class(klass);
|
2014-05-02 15:55:51 -07:00
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
|
2014-09-12 12:50:09 -07:00
|
|
|
void
|
2014-11-11 14:37:47 -08:00
|
|
|
convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
|
2014-09-12 12:50:09 -07:00
|
|
|
{
|
2014-11-11 14:37:47 -08:00
|
|
|
for(efl::eina::iterator<const Eolian_Function> first ( ::eolian_class_functions_get(&klass, EOLIAN_METHOD))
|
|
|
|
, last; first != last; ++first)
|
2014-09-12 12:50:09 -07:00
|
|
|
{
|
2014-11-11 14:37:47 -08:00
|
|
|
Eolian_Function const& func = *first;
|
|
|
|
Eolian_Function_Type const func_type = function_op_type(func);
|
2014-09-12 12:50:09 -07:00
|
|
|
|
2014-11-11 14:37:47 -08:00
|
|
|
if (function_is_constructor(klass, func))
|
2014-09-12 12:50:09 -07:00
|
|
|
{
|
|
|
|
cls.constructors.push_back({
|
2014-09-25 12:09:40 -07:00
|
|
|
function_impl(func),
|
2014-09-12 12:50:09 -07:00
|
|
|
_convert_eolian_parameters(func),
|
2014-11-11 14:37:47 -08:00
|
|
|
convert_comments_function(klass, func)
|
2014-09-12 12:50:09 -07:00
|
|
|
});
|
|
|
|
}
|
2014-11-11 14:37:47 -08:00
|
|
|
else if (function_is_visible(func, func_type))
|
2014-09-12 12:50:09 -07:00
|
|
|
{
|
|
|
|
cls.functions.push_back({
|
|
|
|
function_type(func),
|
|
|
|
function_name(func),
|
2014-09-25 12:09:40 -07:00
|
|
|
function_impl(func),
|
2014-09-12 12:50:09 -07:00
|
|
|
function_return_type(func),
|
|
|
|
_convert_eolian_parameters(func),
|
2014-11-11 14:37:47 -08:00
|
|
|
convert_comments_function(klass, func, eolian_cxx::method)
|
2014-09-12 12:50:09 -07:00
|
|
|
});
|
|
|
|
}
|
2014-11-11 14:37:47 -08:00
|
|
|
}
|
|
|
|
for(efl::eina::iterator<const Eolian_Function> first ( ::eolian_class_functions_get(&klass, EOLIAN_PROPERTY))
|
|
|
|
, last; first != last; ++first)
|
|
|
|
{
|
|
|
|
Eolian_Function const& func = *first;
|
|
|
|
Eolian_Function_Type t = ::eolian_function_type_get(&func);
|
|
|
|
|
|
|
|
if(t == EOLIAN_PROP_GET)
|
|
|
|
{
|
|
|
|
cls.functions.push_back
|
|
|
|
(_convert_property_get_to_function(klass, func));
|
|
|
|
}
|
|
|
|
else if(t == EOLIAN_PROP_SET)
|
|
|
|
{
|
|
|
|
cls.functions.push_back
|
|
|
|
(_convert_property_set_to_function(klass, func));
|
|
|
|
}
|
|
|
|
else if(t == EOLIAN_PROPERTY)
|
|
|
|
{
|
|
|
|
cls.functions.push_back
|
|
|
|
(_convert_property_get_to_function(klass, func));
|
|
|
|
cls.functions.push_back
|
|
|
|
(_convert_property_set_to_function(klass, func));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Error: Inconsistent type for Eolian function \'" << ::eolian_function_name_get(&func) << "\'." << std::endl;
|
|
|
|
throw std::runtime_error("Invalid Eolian function type");
|
|
|
|
}
|
2014-09-12 12:50:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 15:55:51 -07:00
|
|
|
efl::eolian::eo_class
|
2014-07-09 11:55:24 -07:00
|
|
|
convert_eolian_class(const Eolian_Class& klass)
|
2014-05-02 15:55:51 -07:00
|
|
|
{
|
2014-06-30 11:32:52 -07:00
|
|
|
efl::eolian::eo_class cls(eolian_cxx::convert_eolian_class_new(klass));
|
|
|
|
eolian_cxx::convert_eolian_inheritances(cls, klass);
|
2014-11-11 14:37:47 -08:00
|
|
|
eolian_cxx::convert_eolian_functions(cls, klass);
|
2014-06-30 11:32:52 -07:00
|
|
|
eolian_cxx::convert_eolian_events(cls, klass);
|
|
|
|
efl::eolian::eo_class_validate(cls);
|
2014-05-02 15:55:51 -07:00
|
|
|
return cls;
|
|
|
|
}
|
2014-06-30 11:32:52 -07:00
|
|
|
|
|
|
|
} // namespace eolian_cxx {
|