2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
#include <Eolian.h>
|
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
#include <Eolian_Cxx.hh>
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
#include <eolian/mono/logging.hh>
|
2018-04-16 17:44:27 -07:00
|
|
|
#include <eolian/mono/name_helpers.hh>
|
2017-11-23 16:50:16 -08:00
|
|
|
#include <eolian/mono/klass.hh>
|
|
|
|
#include <eolian/mono/enum_definition.hh>
|
|
|
|
#include <eolian/mono/struct_definition.hh>
|
|
|
|
#include <eolian/mono/type_impl.hh>
|
|
|
|
#include <eolian/mono/marshall_type_impl.hh>
|
|
|
|
#include <eolian/mono/marshall_annotation.hh>
|
|
|
|
#include <eolian/mono/function_pointer.hh>
|
2018-05-10 18:00:07 -07:00
|
|
|
#include <eolian/mono/alias_definition.hh>
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
namespace eolian_mono {
|
|
|
|
|
|
|
|
/// Program options.
|
|
|
|
struct options_type
|
|
|
|
{
|
|
|
|
std::vector<std::string> include_dirs;
|
|
|
|
std::string in_file;
|
|
|
|
std::string out_file;
|
|
|
|
std::string dllimport;
|
2018-02-27 04:00:36 -08:00
|
|
|
mutable Eolian_State* state;
|
2017-12-06 08:27:27 -08:00
|
|
|
mutable Eolian_Unit const* unit;
|
2017-11-23 16:50:16 -08:00
|
|
|
int v_major;
|
|
|
|
int v_minor;
|
|
|
|
std::map<const std::string, std::string> references_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parses a CSV file in the format 'filename,library' (without trimming spaces around ',')
|
|
|
|
static std::vector<std::pair<std::string, std::string> >
|
|
|
|
parse_reference(std::string filename)
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string> > ret;
|
|
|
|
std::string delimiter = ",";
|
|
|
|
std::ifstream infile(filename);
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
while (std::getline(infile, line))
|
|
|
|
{
|
|
|
|
size_t pos = line.find(delimiter);
|
|
|
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
throw std::invalid_argument("Malformed mapping. Must be 'filename,library'");
|
|
|
|
|
|
|
|
std::string eo_filename = line.substr(0, pos);
|
|
|
|
std::string library = line.substr(pos + 1);
|
|
|
|
library[0] = std::toupper(library[0]);
|
|
|
|
ret.push_back(std::pair<std::string, std::string>(eo_filename, library));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
opts_check(eolian_mono::options_type const& opts)
|
|
|
|
{
|
|
|
|
if (opts.in_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Nothing to generate?" << std::endl;
|
|
|
|
}
|
|
|
|
else if (opts.out_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Nowhere to generate?" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return true; // valid.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run(options_type const& opts)
|
|
|
|
{
|
|
|
|
const Eolian_Class *klass = NULL;
|
|
|
|
Eina_Iterator *aliases = NULL;
|
|
|
|
const Eolian_Typedecl *tp = NULL;
|
|
|
|
char* dup = strdup(opts.in_file.c_str());
|
|
|
|
std::string basename_input = basename(dup);
|
2018-03-02 14:58:20 -08:00
|
|
|
klass = ::eolian_state_class_by_file_get(opts.state, basename_input.c_str());
|
|
|
|
aliases= ::eolian_state_aliases_by_file_get(opts.state, basename_input.c_str());
|
2017-11-23 16:50:16 -08:00
|
|
|
free(dup);
|
|
|
|
|
|
|
|
std::string class_file_name = opts.out_file;
|
|
|
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
std::ostream_iterator<char> iterator
|
|
|
|
{[&]
|
|
|
|
{
|
|
|
|
if(opts.out_file == "-")
|
|
|
|
return std::ostream_iterator<char>(std::cout);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output_file.open(class_file_name);
|
|
|
|
if (!output_file.good())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Can't open output file: " << class_file_name << std::endl;
|
|
|
|
throw std::runtime_error("");
|
|
|
|
}
|
|
|
|
return std::ostream_iterator<char>(output_file);
|
|
|
|
}
|
|
|
|
}()};
|
|
|
|
|
2018-10-04 00:59:02 -07:00
|
|
|
if (!as_generator("#pragma warning disable CS1591\n").generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null()))
|
|
|
|
throw std::runtime_error("Failed to generate pragma to disable missing docs");
|
|
|
|
|
csharp: Change to new class API.
Summary:
As discussed in T7204:
- Eo Interfaces/mixins -> C# Interfaces with concrete class
implementations
- Eo Regular/Abstracts -> Proper C# classes
- Added some new generators and helper methods.
- Refactored the class generator, splitting into helper methods
Eo handles now are stored only in the "root" class in any given
inheritance tree (generally, Efl.Object), and accessible to each child.
Methods also are defined in a single place instead of repeatedly
generated in everyfile, reducing the size of the generated .dll from
30MB to around 4.5MB.
Mixins are generated as C# interfaces but any regular class it inherits
from is lost, as we can't have interfaces inheriting from regular
classes. This will be dealt with in a later commit.
Summary of API Changes:
- Merged Inherit/Concrete classes. (These suffixes disappear from
regular classes).
- Interface still have implementations with 'Concrete' suffix for when
they are returned from methods.
- Removed 'I' from interface names.
- Removed interfaces for regular/abstract Eo classes.
- Concrete classes for interfaces/mixins hold the event argument struct.
- Removed '_' from classes, enums, structs, etc, as indicated in C#
naming conventions.
- Namespaces are now Camel.Cased.
- Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass
Also renamed the test classes as after the namespace change, the
test namespace Test can conflict with the helper Test namespace.
(And use more meaningful names than Test.Testing...)
Also Fixes T7336 by removing a deprecated example and adding
efl_loop_timer_example to build system.
Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper
fields. The native handlers are used in the manual binding.
Still need to work:
- As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize"
from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on
the interface and implemented "namespaced" in the classes,
requiring the cast to the interface to access the event.
- The Mixin Conundrum. Mixin inheritance will be dealt in a future
commit.
Depends on D7260
Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7451, T7336
Differential Revision: https://phab.enlightenment.org/D7262
2018-11-29 15:04:37 -08:00
|
|
|
if (!as_generator("using System;\n"
|
|
|
|
"using System.Runtime.InteropServices;\n"
|
|
|
|
"using System.Collections.Generic;\n"
|
|
|
|
"using System.ComponentModel;\n")
|
2017-11-23 16:50:16 -08:00
|
|
|
.generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null()))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate file preamble");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto context = efl::eolian::grammar::context_add_tag(eolian_mono::library_context{opts.dllimport,
|
|
|
|
opts.v_major,
|
|
|
|
opts.v_minor,
|
|
|
|
opts.references_map},
|
|
|
|
efl::eolian::grammar::context_null());
|
|
|
|
EINA_ITERATOR_FOREACH(aliases, tp)
|
|
|
|
{
|
2018-05-10 18:00:07 -07:00
|
|
|
if (eolian_typedecl_type_get(tp) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
|
|
|
|
{
|
|
|
|
const Eolian_Function *fp = eolian_typedecl_function_pointer_get(tp);
|
|
|
|
efl::eolian::grammar::attributes::function_def function_def(fp, EOLIAN_FUNCTION_POINTER, tp, opts.unit);
|
|
|
|
if (!eolian_mono::function_pointer.generate(iterator, function_def, context))
|
|
|
|
throw std::runtime_error("Failed to generate function pointer wrapper");
|
|
|
|
}
|
|
|
|
else // Regular aliases
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::alias_def alias(tp, opts.unit);
|
|
|
|
auto alias_cxt = context_add_tag(class_context{class_context::alias}, context);
|
|
|
|
|
|
|
|
if (!eolian_mono::alias_definition.generate(iterator, alias, alias_cxt))
|
|
|
|
throw std::runtime_error("Failed to generate alias.");
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (klass)
|
|
|
|
{
|
2017-12-06 08:27:27 -08:00
|
|
|
efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit);
|
2017-11-23 16:50:16 -08:00
|
|
|
std::vector<efl::eolian::grammar::attributes::klass_def> klasses{klass_def};
|
|
|
|
|
|
|
|
if (!eolian_mono::klass
|
|
|
|
.generate(iterator, klass_def, context))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate class");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
// Enums
|
|
|
|
for (efl::eina::iterator<const Eolian_Typedecl> enum_iterator( ::eolian_state_enums_by_file_get(opts.state, basename_input.c_str()))
|
|
|
|
, enum_last; enum_iterator != enum_last; ++enum_iterator)
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::enum_def enum_(&*enum_iterator, opts.unit);
|
|
|
|
if (!eolian_mono::enum_definition.generate(iterator, enum_, efl::eolian::grammar::context_null()))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate enum");
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
// Structs
|
|
|
|
for (efl::eina::iterator<const Eolian_Typedecl> struct_iterator( ::eolian_state_structs_by_file_get(opts.state, basename_input.c_str()))
|
|
|
|
, struct_last; struct_iterator != struct_last; ++struct_iterator)
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::struct_def struct_(&*struct_iterator, opts.unit);
|
|
|
|
auto structs_cxt = context_add_tag(class_context{class_context::structs}, context);
|
|
|
|
if (!eolian_mono::struct_entities.generate(iterator, struct_, structs_cxt))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate struct");
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
2017-12-06 08:27:27 -08:00
|
|
|
static void
|
|
|
|
state_init(options_type const& opts)
|
|
|
|
{
|
2018-02-27 04:00:36 -08:00
|
|
|
Eolian_State *eos = ::eolian_state_new();
|
2017-12-06 08:27:27 -08:00
|
|
|
if (!eos)
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Eolian failed creating state";
|
|
|
|
assert(false && "Error creating state");
|
|
|
|
}
|
|
|
|
opts.state = eos;
|
|
|
|
opts.unit = (Eolian_Unit*)eos;
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
static void
|
|
|
|
database_load(options_type const& opts)
|
|
|
|
{
|
|
|
|
for (auto src : opts.include_dirs)
|
|
|
|
{
|
2018-03-02 04:30:14 -08:00
|
|
|
if (!::eolian_state_directory_add(opts.state, src.c_str()))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_WARN(eolian_mono::domain)
|
|
|
|
<< "Couldn't load eolian from '" << src << "'.";
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 04:30:14 -08:00
|
|
|
if (!::eolian_state_all_eot_files_parse(opts.state))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Eolian failed parsing eot files";
|
|
|
|
assert(false && "Error parsing eot files");
|
|
|
|
}
|
|
|
|
if (opts.in_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "No input file.";
|
|
|
|
assert(false && "Error parsing input file");
|
|
|
|
}
|
2018-03-02 04:30:14 -08:00
|
|
|
if (!::eolian_state_file_parse(opts.state, opts.in_file.c_str()))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Failed parsing: " << opts.in_file << ".";
|
|
|
|
assert(false && "Error parsing input file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace eolian_mono {
|
|
|
|
|
|
|
|
static void
|
|
|
|
_print_version()
|
|
|
|
{
|
|
|
|
std::cerr
|
|
|
|
<< "Eolian C++ Binding Generator (EFL "
|
|
|
|
<< PACKAGE_VERSION << ")" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_usage(const char *progname)
|
|
|
|
{
|
|
|
|
std::cerr
|
|
|
|
<< progname
|
|
|
|
<< " [options] [file.eo]" << std::endl
|
|
|
|
<< " A single input file must be provided (unless -a is specified)." << std::endl
|
|
|
|
<< "Options:" << std::endl
|
|
|
|
<< " -a, --all Generate bindings for all Eo classes." << std::endl
|
|
|
|
<< " -c, --class <name> The Eo class name to generate code for." << std::endl
|
|
|
|
<< " -D, --out-dir <dir> Output directory where generated code will be written." << std::endl
|
|
|
|
<< " -I, --in <file/dir> The source containing the .eo descriptions." << std::endl
|
|
|
|
<< " -o, --out-file <file> The output file name. [default: <classname>.eo.hh]" << std::endl
|
|
|
|
<< " -n, --namespace <ns> Wrap generated code in a namespace. [Eg: efl::ecore::file]" << std::endl
|
|
|
|
<< " -r, --recurse Recurse input directories loading .eo files." << std::endl
|
|
|
|
<< " -v, --version Print the version." << std::endl
|
|
|
|
<< " -h, --help Print this help." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_assert_not_dup(std::string option, std::string value)
|
|
|
|
{
|
|
|
|
if (value != "")
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) <<
|
|
|
|
"Option -" + option + " already set (" + value + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static eolian_mono::options_type
|
|
|
|
opts_get(int argc, char **argv)
|
|
|
|
{
|
|
|
|
eolian_mono::options_type opts;
|
|
|
|
|
|
|
|
const struct option long_options[] =
|
|
|
|
{
|
|
|
|
{ "in", required_argument, 0, 'I' },
|
|
|
|
{ "out-file", required_argument, 0, 'o' },
|
|
|
|
{ "version", no_argument, 0, 'v' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ "dllimport", required_argument, 0, 'l' },
|
|
|
|
{ "vmaj", required_argument, 0, 'M' },
|
|
|
|
{ "vmin", required_argument, 0, 'm' },
|
|
|
|
{ "references", required_argument, 0, 'r'},
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
const char* options = "I:D:o:c:M:m:ar:vh";
|
|
|
|
|
|
|
|
int c, idx;
|
|
|
|
while ( (c = getopt_long(argc, argv, options, long_options, &idx)) != -1)
|
|
|
|
{
|
|
|
|
if (c == 'I')
|
|
|
|
{
|
|
|
|
opts.include_dirs.push_back(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'o')
|
|
|
|
{
|
|
|
|
_assert_not_dup("o", opts.out_file);
|
|
|
|
opts.out_file = optarg;
|
|
|
|
}
|
|
|
|
else if (c == 'h')
|
|
|
|
{
|
|
|
|
_usage(argv[0]);
|
|
|
|
}
|
|
|
|
else if (c == 'l')
|
|
|
|
{
|
|
|
|
opts.dllimport = optarg;
|
|
|
|
}
|
|
|
|
else if (c == 'M')
|
|
|
|
{
|
|
|
|
opts.v_major = std::stoi(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'm')
|
|
|
|
{
|
|
|
|
opts.v_minor = std::stoi(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'r')
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string> > names = eolian_mono::parse_reference(optarg);
|
|
|
|
for (auto&& p : names)
|
|
|
|
{
|
|
|
|
opts.references_map[p.first] = p.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument processing argument " << optarg << std::endl;
|
|
|
|
_usage(argv[0]);
|
|
|
|
assert(false && e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == 'v')
|
|
|
|
{
|
|
|
|
_print_version();
|
|
|
|
if (argc == 2) exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind == argc-1)
|
|
|
|
{
|
|
|
|
opts.in_file = argv[optind];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eolian_mono::opts_check(opts))
|
|
|
|
{
|
|
|
|
_usage(argv[0]);
|
|
|
|
assert(false && "Wrong options passed in command-line");
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
efl::eina::eina_init eina_init;
|
|
|
|
efl::eolian::eolian_init eolian_init;
|
|
|
|
eolian_mono::options_type opts = opts_get(argc, argv);
|
2017-12-06 08:27:27 -08:00
|
|
|
eolian_mono::state_init(opts);
|
2017-11-23 16:50:16 -08:00
|
|
|
eolian_mono::database_load(opts);
|
|
|
|
eolian_mono::run(opts);
|
|
|
|
}
|
|
|
|
catch(std::exception const& e)
|
|
|
|
{
|
|
|
|
std::cerr << "EOLCXX: Eolian C++ failed generation for the following reason: " << e.what() << std::endl;
|
|
|
|
std::cout << "EOLCXX: Eolian C++ failed generation for the following reason: " << e.what() << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|