doc_data.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*************************************************************************/
  2. /* doc_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef DOC_DATA_H
  31. #define DOC_DATA_H
  32. #include "core/io/xml_parser.h"
  33. #include "core/templates/rb_map.h"
  34. #include "core/variant/variant.h"
  35. struct ScriptMemberInfo {
  36. PropertyInfo propinfo;
  37. String doc_string;
  38. StringName setter;
  39. StringName getter;
  40. bool has_default_value = false;
  41. Variant default_value;
  42. };
  43. class DocData {
  44. public:
  45. struct ArgumentDoc {
  46. String name;
  47. String type;
  48. String enumeration;
  49. String default_value;
  50. bool operator<(const ArgumentDoc &p_arg) const {
  51. if (name == p_arg.name) {
  52. return type < p_arg.type;
  53. }
  54. return name < p_arg.name;
  55. }
  56. };
  57. struct MethodDoc {
  58. String name;
  59. String return_type;
  60. String return_enum;
  61. String qualifiers;
  62. String description;
  63. Vector<ArgumentDoc> arguments;
  64. Vector<int> errors_returned;
  65. bool operator<(const MethodDoc &p_method) const {
  66. if (name == p_method.name) {
  67. // Must be an operator or a constructor since there is no other overloading
  68. if (name.left(8) == "operator") {
  69. if (arguments.size() == p_method.arguments.size()) {
  70. if (arguments.size() == 0) {
  71. return false;
  72. }
  73. return arguments[0].type < p_method.arguments[0].type;
  74. }
  75. return arguments.size() < p_method.arguments.size();
  76. } else {
  77. // Must be a constructor
  78. // We want this arbitrary order for a class "Foo":
  79. // - 1. Default constructor: Foo()
  80. // - 2. Copy constructor: Foo(Foo)
  81. // - 3+. Other constructors Foo(Bar, ...) based on first argument's name
  82. if (arguments.size() == 0 || p_method.arguments.size() == 0) { // 1.
  83. return arguments.size() < p_method.arguments.size();
  84. }
  85. if (arguments[0].type == return_type || p_method.arguments[0].type == p_method.return_type) { // 2.
  86. return (arguments[0].type == return_type) || (p_method.arguments[0].type != p_method.return_type);
  87. }
  88. return arguments[0] < p_method.arguments[0];
  89. }
  90. }
  91. return name < p_method.name;
  92. }
  93. };
  94. struct ConstantDoc {
  95. String name;
  96. String value;
  97. bool is_value_valid = false;
  98. String enumeration;
  99. bool is_bitfield = false;
  100. String description;
  101. bool operator<(const ConstantDoc &p_const) const {
  102. return name < p_const.name;
  103. }
  104. };
  105. struct EnumDoc {
  106. String name = "@unnamed_enum";
  107. bool is_bitfield = false;
  108. String description;
  109. Vector<DocData::ConstantDoc> values;
  110. };
  111. struct PropertyDoc {
  112. String name;
  113. String type;
  114. String enumeration;
  115. String description;
  116. String setter, getter;
  117. String default_value;
  118. bool overridden = false;
  119. String overrides;
  120. bool operator<(const PropertyDoc &p_prop) const {
  121. return name < p_prop.name;
  122. }
  123. };
  124. struct ThemeItemDoc {
  125. String name;
  126. String type;
  127. String data_type;
  128. String description;
  129. String default_value;
  130. bool operator<(const ThemeItemDoc &p_theme_item) const {
  131. // First sort by the data type, then by name.
  132. if (data_type == p_theme_item.data_type) {
  133. return name < p_theme_item.name;
  134. }
  135. return data_type < p_theme_item.data_type;
  136. }
  137. };
  138. struct TutorialDoc {
  139. String link;
  140. String title;
  141. };
  142. struct ClassDoc {
  143. String name;
  144. String inherits;
  145. String category; // FIXME: Wrongly used by VisualScriptPropertySelector, should be removed.
  146. String brief_description;
  147. String description;
  148. Vector<TutorialDoc> tutorials;
  149. Vector<MethodDoc> constructors;
  150. Vector<MethodDoc> methods;
  151. Vector<MethodDoc> operators;
  152. Vector<MethodDoc> signals;
  153. Vector<ConstantDoc> constants;
  154. HashMap<String, String> enums;
  155. Vector<PropertyDoc> properties;
  156. Vector<MethodDoc> annotations;
  157. Vector<ThemeItemDoc> theme_properties;
  158. bool is_script_doc = false;
  159. String script_path;
  160. bool operator<(const ClassDoc &p_class) const {
  161. return name < p_class.name;
  162. }
  163. };
  164. static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
  165. static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
  166. static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
  167. static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
  168. static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc);
  169. static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc);
  170. };
  171. #endif // DOC_DATA_H