efl/src/bin/eolian_mono/eolian/mono/generation_contexts.hh

128 lines
3.3 KiB
C++
Raw Normal View History

/*
* Copyright 2019 by its authors. See AUTHORS.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef EOLIAN_MONO_GENERATION_CONTEXTS_HH
#define EOLIAN_MONO_GENERATION_CONTEXTS_HH
#include <map>
#include "grammar/context.hpp"
#include "grammar/indentation.hpp"
namespace eolian_mono {
struct class_context
{
enum wrapper_kind {
interface,
concrete,
inherit,
inherit_native,
structs,
enums,
function_ptr,
alias,
variables,
};
wrapper_kind current_wrapper_kind;
std::string name;
class_context(wrapper_kind current_wrapper_kind)
: current_wrapper_kind(current_wrapper_kind)
, name()
{}
class_context(wrapper_kind current_wrapper_kind, std::string const& name)
: current_wrapper_kind(current_wrapper_kind)
, name(name)
{}
};
C#: Update C# code-generation to use a new ICustomMarshaler in some string usages that were leaking When `C` calls a function that return/has an out string and it was overwritten by `C#` inherit class the `C` portion wasn't cleaning its copy. Now, when a `C` calls a `C#` delegate function, `Strings` that are `out` values or `return` values use a new marshaler (specific to this case) that uses Eina short lived strings (`Eina_Slstr`) instead of duplicating it with `strdup`, so at some point, the string passed to `C` is deleted. To do so, a `direction_context` (a new `Context` at `generation_contexts.hh`) was created. It is only used when a C# delegate is being called from C (so this context is only set in `function_definition.hh` and `property_definition.hh`, where it is set to `native_to_manage` to indicate that it is a native call to a managed function). When this `direction_context` is set and the `String` being marshaled is not marked with an `@move` tag and it is an `out` or `return` value, the new `StringOutMarshaler` (implemented at `iwrapper.cs`) is used (instead of `StringKeepOwnershipMarshaler`). When marshaling a managed data to native this marshaler uses eina short lived string (`Eina_Slstr`) that will be automatically deleted. This delete is bounded to "the loop of the current thread or until the clear function is called explicitly" as said at `src/lib/eina/eina_slstr.h`. Reviewed-by: Felipe Magno de Almeida <felipe@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D11434
2020-02-28 07:58:08 -08:00
struct direction_context
{
enum direction {
native_to_managed,
managed_to_native,
};
direction current_direction;
direction_context(direction current_direction)
: current_direction(current_direction)
{}
};
struct indentation_context
{
constexpr indentation_context(indentation_context const& other) = default;
constexpr indentation_context(efl::eolian::grammar::scope_tab_generator indent)
: indent(indent)
{}
constexpr indentation_context(int n)
: indent(n)
{}
constexpr indentation_context(int n, int m)
: indent(n, m)
{}
efl::eolian::grammar::scope_tab_generator indent;
};
template <typename Context>
inline constexpr efl::eolian::grammar::scope_tab_generator const& current_indentation(Context const& context)
{
return efl::eolian::grammar::context_find_tag<indentation_context>(context).indent;
}
template <typename Context>
inline constexpr Context change_indentation(efl::eolian::grammar::scope_tab_generator const& indent, Context const& context)
{
return efl::eolian::grammar::context_replace_tag(indentation_context(indent), context);
}
struct library_context
{
std::string library_name;
int v_major;
int v_minor;
std::map<const std::string, std::string> references;
const std::string actual_library_name(const std::string& filename) const;
};
const std::string
library_context::actual_library_name(const std::string& filename) const
{
// Libraries mapped follow the efl.Libs.NAME scheme.
// TODO What about references from outside efl (not present in the efl.Libs class?)
auto ref = references.find(filename);
if (ref != references.end())
return "efl.Libs." + ref->second;
// Fallback to original behaviour with explicit library name
return '"' + library_name + '"';
}
struct eolian_state_context {
const Eolian_State *state;
};
struct options_context {
bool want_beta;
mono-docs: Allow embedding external examples Summary: New option added to eolian_gen: -e <dir> This specifies a directory to search for examples. If a file is found with the same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full contents will be embedded in the documentation for that class or method within <example> and <code> tags. This is, in turn, is parsed by DocFX and shown in Example boxes in the generated pages. If an example file is not found, no examples are embedded for that object. If -e is not used, no examples are embedded for any object. New option added to meson: mono-examples-dir to point to the examples directory. This directory is then passed to eolian_mono through -e. Do not use it (or define it to nothing) to disable example embedding. No performance drop has been observed because of these extra tests. Right now examples can only be given for base classes, not for derived ones (i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a later commit. Feature Depends on D8587 Test Plan: Create an examples folder and put some files in it: ``` mkdir /tmp/examples echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs ``` Configure meson to embed examples and build: ``` meson configure -Dmono-examples-dir=/tmp/examples ninja ``` Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags, or run DocFX and bask in the glory of documentation pages with examples: ``` cd doc/docfx ./gendoc.sh ``` Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
std::string examples_dir;
};
}
#endif