genbase.hpp 3.0 KB

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