fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5.  
  6. #include <boost/variant.hpp>
  7. #include <boost/optional.hpp>
  8.  
  9. using string = std::string;
  10.  
  11. namespace cppmodel {
  12.  
  13.  
  14. struct Class;
  15. using Type = boost::variant<Class*,string>;
  16.  
  17. struct Var{
  18. string name, value;
  19. Type type;
  20. bool is_volatile = false;
  21. bool is_mutable = false;
  22. bool is_const = false;
  23. bool is_static = false;
  24. bool is_ref = false;
  25. std::uint8_t is_pointer = 0; // 0 false, otherwise pointer depth in *
  26. std::uint8_t has_bits = 0;//bits
  27. };
  28.  
  29. using BasicArgumentList = std::vector<Var>;
  30.  
  31. struct Using
  32. {
  33. string aliasname,aliastype;
  34. boost::optional<BasicArgumentList> arguments;
  35. };
  36.  
  37. struct Function{
  38. string name,test,body,comment;
  39. std::vector<Type> arguments;
  40. Type rtype = "void";
  41. boost::optional<BasicArgumentList> template_arguments;
  42. bool isTemplate()const {return template_arguments.is_initialized() && !template_arguments.get().empty();}
  43. bool is_noexcept = true;
  44. bool is_inline = false;
  45. bool is_static = false;
  46. };
  47.  
  48. struct Default{};
  49. struct Delete{};
  50. using default_or_delete = boost::optional<boost::variant<Default,Delete>>;
  51.  
  52. struct Ref{};
  53. struct RefRef{};
  54. using RefQualifier = boost::optional<boost::variant<Ref,RefRef> >;
  55.  
  56. struct Method{
  57. string name,test,body,comment;
  58. std::vector<Type> arguments;
  59. Type rtype = "void";
  60. bool is_virtual = false, is_pure_virtual = false, is_const = false;
  61. boost::optional<BasicArgumentList> template_arguments;
  62. default_or_delete dod;
  63. RefQualifier refqualifier;
  64. bool is_noexcept = true;
  65. bool is_inline = false;
  66. bool is_static = false;
  67. bool is_override = false;
  68. };
  69.  
  70. struct Constructor{
  71. string test,body;
  72. std::vector<Type> arguments;
  73. Class& type;
  74. boost::optional<BasicArgumentList> template_arguments;
  75. default_or_delete dod;
  76. bool is_noexcept = true;
  77. };
  78.  
  79. struct Private{};
  80. struct Public{};
  81. struct Protected{};
  82.  
  83. using Access = boost::variant<Private,Public,Protected>;
  84.  
  85. struct Destructor{
  86. string test,body;
  87. Class& type;
  88. Access access;
  89. default_or_delete dod;
  90. bool is_virtual = false;
  91. bool is_inline = false;
  92. bool is_friend = false;
  93. };
  94.  
  95. struct Parent
  96. {
  97. Type type;
  98. Access access;
  99. bool is_virtual;
  100. };
  101.  
  102. using ClassMembers = boost::variant<Class*, Var,Function,Method,Constructor,Using>;
  103.  
  104. struct Class
  105. {
  106. string test,name,comment;
  107. boost::optional<Destructor> destructor;
  108. std::multimap<Access,ClassMembers> members;
  109. std::vector<Parent> parents;
  110. boost::optional<BasicArgumentList> template_arguments;
  111. bool isTemplate()const{return template_arguments.is_initialized() && !template_arguments.get().empty();}
  112. bool is_final = false;
  113. bool is_class = false;
  114. bool is_noexcept = true;
  115. };
  116.  
  117. class Namespace;
  118. using NamespaceMembers = boost::variant<string,Namespace*, Var, Function, Class,Using>;
  119.  
  120. struct Namespace{
  121. string name;
  122. std::vector<NamespaceMembers> members;
  123. };
  124.  
  125. }
  126.  
  127. int main(int argc, char *argv[])
  128. {
  129. using namespace cppmodel;
  130. Namespace root{"cppmodel",{}};
  131. auto& members = root.members;
  132. members.push_back("struct Class;");
  133. Using type{"type","boost::variant<Class*,string>",{}};
  134. members.push_back(type);
  135.  
  136. std::cout << "Hello World!" << std::endl;
  137. return 0;
  138. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:10: fatal error: 'boost/variant.hpp' file not found
#include <boost/variant.hpp>
         ^
1 error generated.
stdout
Standard output is empty