ASResult.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // Copyright (c) 2008-2022 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <memory>
  24. #include <sstream>
  25. #include <string>
  26. #include <vector>
  27. namespace ASBindingGenerator
  28. {
  29. class ASGeneratedFile_Base
  30. {
  31. protected:
  32. // Result file path
  33. std::string outputFilePath_;
  34. public:
  35. // Wrappers
  36. std::stringstream glue_;
  37. // Registration function body
  38. std::stringstream reg_;
  39. // Write result to file
  40. virtual void Save() {};
  41. };
  42. class ASGeneratedFile_WithRegistrationFunction : public ASGeneratedFile_Base
  43. {
  44. protected:
  45. // Registration function name
  46. std::string functionName_;
  47. public:
  48. ASGeneratedFile_WithRegistrationFunction(const std::string& outputFilePath, const std::string& functionName);
  49. };
  50. class ASGeneratedFile_Members : public ASGeneratedFile_WithRegistrationFunction
  51. {
  52. public:
  53. using ASGeneratedFile_WithRegistrationFunction::ASGeneratedFile_WithRegistrationFunction;
  54. void Save() override;
  55. };
  56. class ASGeneratedFile_Templates : public ASGeneratedFile_Base
  57. {
  58. public:
  59. ASGeneratedFile_Templates(const std::string& outputFilePath);
  60. // Write result to file
  61. void Save() override;
  62. };
  63. struct ProcessedEnum
  64. {
  65. std::string name_; // Used for sorting
  66. std::string comment_; // Location
  67. std::vector<std::string> glue_; // Can be empty
  68. std::string insideDefine_; // Can be empty
  69. std::vector<std::string> registration_; // Or warning message
  70. // Used for sorting
  71. bool operator <(const ProcessedEnum& rhs) const;
  72. };
  73. struct ProcessedGlobalFunction
  74. {
  75. std::string name_; // Used for sorting
  76. std::string comment_; // Location
  77. std::string glue_; // Can be empty
  78. std::string insideDefine_; // Can be empty
  79. std::string registration_; // Or warning message
  80. // Used for sorting
  81. bool operator <(const ProcessedGlobalFunction& rhs) const;
  82. };
  83. struct ProcessedGlobalVariable
  84. {
  85. std::string name_; // Used for sorting
  86. std::string comment_; // Location
  87. std::string insideDefine_; // Can be empty
  88. std::string registration_; // Or warning message
  89. // Used for sorting
  90. bool operator <(const ProcessedGlobalVariable& rhs) const;
  91. };
  92. struct Registration
  93. {
  94. std::string comment_;
  95. std::string glue_;
  96. std::vector<std::string> registration_;
  97. };
  98. struct SpecialMethodRegistration
  99. {
  100. std::string comment_; // C++ declaration / location for default constructor
  101. std::string glue_;
  102. std::string registration_; // Or warning message
  103. };
  104. struct RegisterObjectMethodArgs
  105. {
  106. std::vector<std::string> asDeclarations_; // String
  107. std::string funcPointer_; // asSFuncPtr
  108. std::string callConv_; // asDWORD
  109. };
  110. struct MethodRegistration
  111. {
  112. std::string name_; // Used for sorting
  113. std::string cppDeclaration_;
  114. std::string glue_;
  115. RegisterObjectMethodArgs registration_;
  116. };
  117. struct RegisterGlobalFunctionArgs
  118. {
  119. std::vector<std::string> asDeclarations_; // String
  120. std::string funcPointer_; // asSFuncPtr
  121. std::string callConv_; // asDWORD
  122. };
  123. struct StaticMethodRegistration
  124. {
  125. std::string name_; // Used for sorting
  126. std::string cppDeclaration_;
  127. std::string glue_;
  128. RegisterGlobalFunctionArgs registration_;
  129. };
  130. struct RegisterObjectPropertyArgs
  131. {
  132. std::vector<std::string> asDeclarations_; // String
  133. std::string byteOffset_; // int
  134. };
  135. struct FieldRegistration
  136. {
  137. std::string name_; // Used for sorting
  138. std::string cppDeclaration_;
  139. RegisterObjectPropertyArgs registration_;
  140. };
  141. struct RegisterGlobalPropertyArgs
  142. {
  143. std::vector<std::string> asDeclarations_; // String
  144. std::string pointer_; // void*
  145. };
  146. struct StaticFieldRegistration
  147. {
  148. std::string name_; // Used for sorting
  149. std::string cppDeclaration_;
  150. RegisterGlobalPropertyArgs registration_;
  151. };
  152. /*
  153. struct RegisterObjectBehaviourArgs
  154. {
  155. std::string behaviour_; // asEBehaviours
  156. std::vector<std::string> asDeclarations_; // String
  157. std::string funcPointer_; // asSFuncPtr
  158. std::string callConv_; // asDWORD
  159. };
  160. struct BehaviorRegistration
  161. {
  162. std::string name_; // Used for sorting
  163. std::string cppDeclaration_;
  164. //std::string glue_;
  165. RegisterObjectBehaviourArgs registration_;
  166. };
  167. */
  168. struct MemberRegistrationError
  169. {
  170. std::string name_; // Used for sorting
  171. std::string comment_; // C++ declaration / location
  172. std::string message_;
  173. // Used for sorting
  174. bool operator <(const MemberRegistrationError& rhs) const;
  175. };
  176. struct ProcessedClass
  177. {
  178. std::string name_;
  179. std::string dirName_;
  180. std::string insideDefine_; // Can be empty
  181. std::string comment_; // Class location
  182. std::string objectTypeRegistration_; // engine->RegisterObjectType(...); or warning message
  183. int inherianceDeep_ = 0; // Used for sorting
  184. // Used for sorting
  185. bool operator <(const ProcessedClass& rhs) const;
  186. std::shared_ptr<SpecialMethodRegistration> defaultConstructor_;
  187. std::vector<SpecialMethodRegistration> nonDefaultConstructors_;
  188. std::shared_ptr<SpecialMethodRegistration> destructor_;
  189. std::vector<MemberRegistrationError> unregisteredSpecialMethods_;
  190. //std::vector<MethodRegistration> methods_;
  191. //std::vector<StaticMethodRegistration> staticMethods_;
  192. //std::vector<MemberRegistrationError> unregisteredStaticMethods_;
  193. //std::vector<FieldRegistration> fields_;
  194. //std::vector<MemberRegistrationError> unregisteredFields_;
  195. //std::vector<MethodRegistration> wrappedFields_;
  196. //std::vector<StaticFieldRegistration> staticFields_;
  197. //std::vector<MemberRegistrationError> unregisteredStaticFields_;
  198. std::vector<std::string> additionalLines_;
  199. bool noBind_ = false;
  200. std::vector<std::string> baseClassNames_;
  201. std::vector<std::string> subclassRegistrations_;
  202. // Base class members that were hidden in this class (c++ declarations)
  203. /*std::vector<std::string> hiddenMethods_;
  204. std::vector<std::string> hiddenStaticMethods_;
  205. std::vector<std::string> hiddenFields_;
  206. std::vector<std::string> hiddenStaticFields_;*/
  207. std::vector<Registration> templateMethods_;
  208. std::vector<MemberRegistrationError> unregisteredTemplateMethods_;
  209. std::vector<Registration> personalMethods_;
  210. std::vector<MemberRegistrationError> unregisteredPersonalMethods_;
  211. std::vector<Registration> templateStaticMethods_;
  212. std::vector<MemberRegistrationError> unregisteredTemplateStaticMethods_;
  213. std::vector<Registration> personalStaticMethods_;
  214. std::vector<MemberRegistrationError> unregisteredPersonalStaticMethods_;
  215. std::vector<Registration> personalFields_;
  216. std::vector<MemberRegistrationError> unregisteredPersonalFields_;
  217. std::vector<Registration> templateFields_;
  218. std::vector<MemberRegistrationError> unregisteredTemplateFields_;
  219. std::vector<Registration> personalStaticFields_;
  220. std::vector<MemberRegistrationError> unregisteredPersonalStaticFields_;
  221. std::vector<Registration> templateStaticFields_;
  222. std::vector<MemberRegistrationError> unregisteredTemplateStaticFields_;
  223. };
  224. namespace Result
  225. {
  226. extern std::vector<ProcessedEnum> enums_;
  227. extern std::vector<ProcessedGlobalFunction> globalFunctions_;
  228. extern std::vector<ProcessedGlobalVariable> globalVariables_;
  229. extern std::vector<ProcessedClass> classes_;
  230. // Add header to lists if not added yet
  231. void AddHeader(const std::string& headerFile);
  232. }
  233. } // namespace ASBindingGenerator