2
0

doc_data.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*************************************************************************/
  2. /* doc_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/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 a constructor since there is no overloading.
  68. // We want this arbitrary order for a class "Foo":
  69. // - 1. Default constructor: Foo()
  70. // - 2. Copy constructor: Foo(Foo)
  71. // - 3+. Other constructors Foo(Bar, ...) based on first argument's name
  72. if (arguments.size() == 0 || p_method.arguments.size() == 0) { // 1.
  73. return arguments.size() < p_method.arguments.size();
  74. }
  75. if (arguments[0].type == return_type || p_method.arguments[0].type == p_method.return_type) { // 2.
  76. return (arguments[0].type == return_type) || (p_method.arguments[0].type != p_method.return_type);
  77. }
  78. return arguments[0] < p_method.arguments[0];
  79. }
  80. return name < p_method.name;
  81. }
  82. };
  83. struct ConstantDoc {
  84. String name;
  85. String value;
  86. bool is_value_valid = false;
  87. String enumeration;
  88. String description;
  89. bool operator<(const ConstantDoc &p_const) const {
  90. return name < p_const.name;
  91. }
  92. };
  93. struct EnumDoc {
  94. String name = "@unnamed_enum";
  95. String description;
  96. Vector<DocData::ConstantDoc> values;
  97. };
  98. struct PropertyDoc {
  99. String name;
  100. String type;
  101. String enumeration;
  102. String description;
  103. String setter, getter;
  104. String default_value;
  105. bool overridden = false;
  106. bool operator<(const PropertyDoc &p_prop) const {
  107. return name < p_prop.name;
  108. }
  109. };
  110. struct ThemeItemDoc {
  111. String name;
  112. String type;
  113. String data_type;
  114. String description;
  115. String default_value;
  116. bool operator<(const ThemeItemDoc &p_theme_item) const {
  117. return name < p_theme_item.name;
  118. }
  119. };
  120. struct TutorialDoc {
  121. String link;
  122. String title;
  123. };
  124. struct ClassDoc {
  125. String name;
  126. String inherits;
  127. String category;
  128. String brief_description;
  129. String description;
  130. Vector<TutorialDoc> tutorials;
  131. Vector<MethodDoc> constructors;
  132. Vector<MethodDoc> methods;
  133. Vector<MethodDoc> operators;
  134. Vector<MethodDoc> signals;
  135. Vector<ConstantDoc> constants;
  136. Map<String, String> enums;
  137. Vector<PropertyDoc> properties;
  138. Vector<ThemeItemDoc> theme_properties;
  139. bool is_script_doc = false;
  140. String script_path;
  141. bool operator<(const ClassDoc &p_class) const {
  142. return name < p_class.name;
  143. }
  144. };
  145. static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
  146. static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
  147. static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
  148. static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
  149. static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc);
  150. static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc);
  151. };
  152. #endif // DOC_DATA_H