doc_data.h 5.5 KB

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