1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#ifndef FUNCTION_HPP
#define FUNCTION_HPP
#include "genbase.hpp"
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
struct ElementFunction
{
// type of function; method, etc
std::string kind;
// GIR name
std::string name;
// otherwise descriptive name (e.g. original C name)
std::string c_id;
// expression defining function
std::string functionexp;
bool throws{};
// represents symbol in lib
// (which can be linked to or dlsym'ed)
bool lib_symbol{};
std::string shadows;
};
// parameter data
constexpr static const int INDEX_DEFAULT = -10;
struct FunctionParameter
{
std::string name;
GeneratorBase::ArgInfo tinfo{};
// deduced C type
std::string ptype;
bool instance{};
std::string direction;
std::string transfer{TRANSFER_NOTHING};
// index
int closure{INDEX_DEFAULT}, destroy{INDEX_DEFAULT};
int callerallocates{};
std::string scope;
bool optional{};
bool nullable{};
};
using Parameter = FunctionParameter;
// info defining function to construct declaration/definition
// (some parts not relevant for signal/callback)
struct FunctionDefinition
{
// return (and optionally additional outputs)
struct Output
{
// cpp type of output
std::string type;
// expression (value of output)
std::string value;
};
struct ArgTrait
{
// transfer (original attribute)
std::string transfer;
// inout parameter
bool inout{};
// applicable/relevant arguments (indexed as usual; see below)
// usually only 1 (to 1)
// for callback; function, userdata[, destroy]
// for sized arrays; data, size
// (other containers only need 1 and handled as usual)
std::vector<int> args;
// custom type trait
std::string custom{};
};
// GIR name (empty if not valid)
std::string name;
// statements preceding wrapped call (excluding final ;)
std::vector<std::string> pre_call;
// idem, post call
std::vector<std::string> post_call;
// assembled outputs (first one is return value, if any, could be empty)
std::vector<Output> cpp_outputs;
// parts that make up the C call (...)
// indexed by param number (instance = -1)
std::map<int, std::string> c_call;
// parts that make up the ( ... ) decl/def
// (similarly indexed/sorted)
std::map<int, std::string> cpp_decl;
// callee; trait info of (callback) parameters
// (lowest one is for return; always present)
// (except if fallback virtual method)
std::map<int, ArgTrait> arg_traits;
// extra parameters in a callee (= cb) declaration not present in callforward
// (to deal with cb sized array output0
std::map<int, std::string> cpp_decl_extra;
// function (expression) to call
std::string c_callee;
// format with single placeholder for call (constructed based on all above)
std::string ret_format;
// parts used for callforward generation of callback type
// (callforward = C++ signature which then calls a C function)
// (callback = C signature which then calls a C++ function)
// typedef of C function to call
std::string cf_ctype;
// (derived) C signature (without instance parameter if virtual method)
std::string c_sig;
};
std::string make_arg_traits(
const std::map<int, FunctionDefinition::ArgTrait> &traits,
const std::string &c_sig);
FunctionDefinition process_element_function(GeneratorContext &_ctx,
const std::string _ns, const pt::ptree::value_type &entry,
std::ostream &out, std::ostream &impl, const std::string &klass,
const std::string &klasstype, GeneratorBase::DepsSet &deps,
std::ostream *call_args, bool allow_deprecated);
FunctionDefinition process_element_function(GeneratorContext &_ctx,
const std::string _ns, const ElementFunction &func,
const std::vector<Parameter> ¶ms, std::ostream &out, std::ostream &impl,
const std::string &klass, const std::string &klasstype,
GeneratorBase::DepsSet &deps);
#endif // FUNCTION_HPP
|