Debian Codegraph @

tools/genbase.hpp

raw symbols SCIP
1 #ifndef GENBASE_HPP
2 #define GENBASE_HPP
3
4 #include "common.hpp"
5 #include "genutils.hpp"
6 #include "repository.hpp"
7
8 #include <set>
9
10 struct GeneratorOptions
11 {
12 // dir in which to generate
13 std::string rootdir;
14 // generate implementation classes
15 bool classimpl;
16 // generate fallback methods (for class implementation)
17 bool classfull;
18 // use dlopen/dlsym for generated call
19 bool dl;
20 // use expected<> return iso exception throwing
21 bool expected;
22 // generate const methods
23 bool const_method;
24 // generate top-level helpers in rootdir
25 bool output_top;
26 // only generate/overwrite output if changed
27 bool only_changed;
28 // min number of non-required function arguments
29 // that triggers generation a CallArgs variant
30 int call_args;
31 // also generate collection signature for input collection of basic type
32 bool basic_collection;
33 };
34
35 struct GeneratorContext
36 {
37 GeneratorOptions &options;
38 Repository &repo;
39 const Matcher &match_ignore;
40 const Matcher &match_sup;
41 // generated during processing
42 std::set<std::string> &suppressions;
43 };
44
45 class GeneratorBase
46 {
47 protected:
48 GeneratorContext &ctx;
49 std::string ns;
50 const std::string indent = " ";
51
52 public:
53 GeneratorBase(GeneratorContext &_ctx, const std::string _ns);
54
55 struct ArgTypeInfo : public TypeInfo
56 {
57 // c:type as parsed from type element
58 // (no const info for array or filename arg)
59 // (empty for void, and possibly property or signal)
60 std::string ctype;
61
62 // return CppType or reference CppType (if non-owning boxed transfer)
63 std::string cppreftype(const std::string transfer) const
64 {
65 if ((flags & TYPE_BOXED) && transfer != TRANSFER_FULL)
66 return cpptype + GI_SUFFIX_REF;
67 // string case
68 if ((flags & TYPE_CLASS) && (flags & TYPE_BASIC) &&
69 transfer != TRANSFER_FULL)
70 return cpptype + "_v";
71 return cpptype;
72 }
73 };
74
75 // the above along with info on contained element
76 // (as provided typically within <type> element in parameter or so)
77 // * first only relevant for array, lists and maps
78 // * second only for maps
79 // * first and second do not have ctype info
80 // * in case of array, no cpptype info on primary
81 // * in case of (GS)List etc, primary specifies the particular type
82 struct ArgInfo : public ArgTypeInfo
83 {
84 // container element types
85 ArgTypeInfo first, second;
86 // array
87 int length = -1;
88 bool zeroterminated = false;
89 int fixedsize = 0;
90 };
91
92 std::string qualify(const std::string &cpptype, int flags) const;
93
94 void parse_typeinfo(const std::string &girname, TypeInfo &result) const;
95
96 // if routput != nullptr, also place result in output
97 // (possibly a partial one if exception is thrown)
98 ArgInfo parse_arginfo(
99 const pt::ptree &node, ArgInfo *routput = nullptr) const;
100
101 static std::string make_ctype(
102 const ArgInfo &info, const std::string &direction, bool callerallocates);
103
104 // set of (ns, dep), where dep = [struct|class ]type
105 using DepsSet = std::set<std::pair<std::string, std::string>>;
106 void track_dependency(DepsSet &deps, const ArgInfo &info) const;
107
108 static std::string make_wrap_format(const ArgInfo &info,
109 const std::string &transfer, const std::string &outtype = {});
110
111 static std::string get_transfer_parameter(
112 const std::string &transfer, bool _type = false);
113
114 bool check_suppression(const std::string &ns, const std::string &kind,
115 const std::string &name) const;
116 };
117 #endif // GENBASE_HPP