Skip to content

Commit

Permalink
Added doc gen for structs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlupugla committed Sep 21, 2024
1 parent e4e024a commit 16ccd37
Show file tree
Hide file tree
Showing 8 changed files with 751 additions and 264 deletions.
24 changes: 24 additions & 0 deletions core/doc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ void DocData::property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_propert
p_property.overridden = false;
}

void DocData::struct_doc_from_structinfo(DocData::StructDoc &p_struct, const StructInfo &p_structinfo) {
p_struct.name = p_structinfo.name;
// TODO: what about description?

p_struct.properties.resize(p_structinfo.count);
for (int i = 0; i < p_structinfo.count; i++) {
PropertyDoc property_doc;
property_doc.name = p_structinfo.names[i];
Variant::Type type = p_structinfo.types[i];
if (type == Variant::OBJECT) {
property_doc.type = p_structinfo.class_names[i];
} else if (type == Variant::NIL) {
property_doc.type = "Variant";
} else {
property_doc.type = Variant::get_type_name(type);
}
if (type != Variant::OBJECT) {
property_doc.default_value = get_default_value_string(p_structinfo.default_values[i]);
}
// TODO: what about description?
p_struct.properties.write[i] = property_doc;
}
}

void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc) {
p_method.name = p_methodinfo.name;
p_method.description = p_desc;
Expand Down
78 changes: 78 additions & 0 deletions core/doc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,67 @@ class DocData {
}
};

struct StructDoc {
String name;
String description;
Vector<PropertyDoc> properties;
bool is_deprecated = false;
bool is_experimental = false;
bool operator<(const StructDoc &p_struct) const {
return name < p_struct.name;
}
static StructDoc from_dict(const Dictionary &p_dict) {
StructDoc doc;

if (p_dict.has("name")) {
doc.name = p_dict["name"];
}

if (p_dict.has("description")) {
doc.description = p_dict["description"];
}

Array properties;
if (p_dict.has("properties")) {
properties = p_dict["properties"];
}
for (int i = 0; i < properties.size(); i++) {
doc.properties.push_back(PropertyDoc::from_dict(properties[i]));
}

if (p_dict.has("is_experimental")) {
doc.is_experimental = p_dict["is_experimental"];
}

return doc;
}
static Dictionary to_dict(const StructDoc &p_doc) {
Dictionary dict;

if (!p_doc.name.is_empty()) {
dict["name"] = p_doc.name;
}

if (!p_doc.description.is_empty()) {
dict["description"] = p_doc.description;
}

if (!p_doc.properties.is_empty()) {
Array properties;
for (int i = 0; i < p_doc.properties.size(); i++) {
properties.push_back(PropertyDoc::to_dict(p_doc.properties[i]));
}
dict["properties"] = properties;
}

dict["is_deprecated"] = p_doc.is_deprecated;

dict["is_experimental"] = p_doc.is_experimental;

return dict;
}
};

struct ClassDoc {
String name;
String inherits;
Expand All @@ -713,6 +774,7 @@ class DocData {
HashMap<String, EnumDoc> enums;
Vector<PropertyDoc> properties;
Vector<MethodDoc> annotations;
Vector<StructDoc> structs;
Vector<ThemeItemDoc> theme_properties;
bool is_deprecated = false;
String deprecated_message;
Expand Down Expand Up @@ -818,6 +880,14 @@ class DocData {
doc.annotations.push_back(MethodDoc::from_dict(annotations[i]));
}

Array structs;
if (p_dict.has("structs")) {
structs = p_dict["structs"];
}
for (int i = 0; i < structs.size(); i++) {
doc.structs.push_back(StructDoc::from_dict(structs[i]));
}

Array theme_properties;
if (p_dict.has("theme_properties")) {
theme_properties = p_dict["theme_properties"];
Expand Down Expand Up @@ -947,6 +1017,13 @@ class DocData {
dict["annotations"] = annotations;
}

if (!p_doc.structs.is_empty()) {
Array structs;
for (int i = 0; i < p_doc.structs.size(); i++) {
structs.push_back(StructDoc::to_dict(p_doc.structs[i]));
}
}

if (!p_doc.theme_properties.is_empty()) {
Array theme_properties;
for (int i = 0; i < p_doc.theme_properties.size(); i++) {
Expand Down Expand Up @@ -982,6 +1059,7 @@ class DocData {
static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
static void struct_doc_from_structinfo(DocData::StructDoc &p_struct, const StructInfo &p_structinfo);

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

unknown type name 'StructInfo'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

unknown type name 'StructInfo'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

unknown type name 'StructInfo'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

unknown type name 'StructInfo'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ',' before '&'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ',' before '&'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

'StructInfo' does not name a type

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ',' before '&'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ',' before '&'

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 1062 in core/doc_data.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ',' before '&'
static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc);
static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc);
Expand Down
31 changes: 31 additions & 0 deletions doc/class.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,37 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="structs" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="struct" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="member" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="type" use="required"/>
<xs:attribute type="xs:string" name="default" use="required"/>
<xs:attribute type="xs:string" name="enum" use="optional" />
<xs:attribute type="xs:boolean" name="is_bitfield" use="optional" />
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="description" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="annotations" minOccurs="0">
<xs:complexType>
<xs:sequence>
Expand Down
9 changes: 6 additions & 3 deletions doc/tools/doc_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"description",
"methods",
"constants",
"structs",
"members",
"theme_items",
"signals",
Expand All @@ -78,6 +79,7 @@
"Desc.",
"Methods",
"Constants",
"Structs",
"Members",
"Theme Items",
"Signals",
Expand Down Expand Up @@ -191,6 +193,7 @@ def __init__(self, name: str = ""):
self.progresses: Dict[str, ClassStatusProgress] = {
"methods": ClassStatusProgress(),
"constants": ClassStatusProgress(),
"structs": ClassStatusProgress(),
"members": ClassStatusProgress(),
"theme_items": ClassStatusProgress(),
"signals": ClassStatusProgress(),
Expand Down Expand Up @@ -239,7 +242,7 @@ def make_output(self) -> Dict[str, str]:
)
items_progress = ClassStatusProgress()

for k in ["methods", "constants", "members", "theme_items", "signals", "constructors", "operators"]:
for k in ["methods", "constants", "structs", "members", "theme_items", "signals", "constructors", "operators"]:
items_progress += self.progresses[k]
output[k] = self.progresses[k].to_configured_colored_string()

Expand Down Expand Up @@ -284,7 +287,7 @@ def generate_for_class(c: ET.Element):
descr = sub_tag.find("description")
has_descr = (descr is not None) and (descr.text is not None) and len(descr.text.strip()) > 0
status.progresses[tag.tag].increment(is_deprecated or is_experimental or has_descr)
elif tag.tag in ["constants", "members", "theme_items"]:
elif tag.tag in ["constants", "structs", "members", "theme_items"]:
for sub_tag in list(tag):
if sub_tag.text is not None:
is_deprecated = "deprecated" in sub_tag.attrib
Expand Down Expand Up @@ -327,7 +330,7 @@ def generate_for_class(c: ET.Element):
sys.exit(1)

if flags["i"]:
for r in ["methods", "constants", "members", "signals", "theme_items"]:
for r in ["methods", "constants", "structs", "members", "signals", "theme_items"]:
index = table_columns.index(r)
del table_column_names[index]
del table_columns[index]
Expand Down
Loading

0 comments on commit 16ccd37

Please sign in to comment.