docs: add support for :override-doc in method declarations as well as documenting state handlers (#2139)

Adding support for better child-type method docstrings. This is a
problem unique to methods.

Usually, a child-type will have the same signature and a common name
will apply, but the implementation is different. This means, you
probably want a different docstring to describe what is happening.

Currently this is possible to do via `:replace`. The problem with
replace is two fold:
- a replaced method ends up in the generated `deftype`...because you
usually change the signature!
- we don't put docstrings in the `deftype` in normal GOAL, this is just
something we do for the `all-types` file (they go in the `defmethod`
instead)
- more importantly, this means anytime you now want to change the
parent's name/args/return type -- you have to apply that change
everywhere.

So this is a better design you can now just declare the method like so:
```clj
(:override-doc "my new docstring" <method_id>)
```

And internally a pseudo-replaced method will be added, but it will
inherit everything from the parent (except the docstring of course)

Unrelated - I also made all the keyword args for declaring methods not
depend on ordering

This also adds support for documenting virtual and non-virtual state
handlers. For example:

```clj
  (:states
    (part-tester-idle (:event "test") symbol))
```

or

```clj
(idle () _type_ :state (:event "test") 20)
```

I will probably add the ability to give some sort of over-view docstring
at a later date.

Co-authored-by: water <awaterford111445@gmail.com>
This commit is contained in:
Tyler Wilding
2023-01-21 20:45:45 -05:00
committed by GitHub
parent e5d6ac1c41
commit abf61a94fb
65 changed files with 793 additions and 472 deletions
+27 -1
View File
@@ -83,8 +83,34 @@ goos::Object final_output_lambda(const Function& func) {
}
}
goos::Object final_output_defstate_anonymous_behavior(const Function& func) {
goos::Object final_output_defstate_anonymous_behavior(const Function& func,
const DecompilerTypeSystem& dts) {
std::vector<goos::Object> inline_body;
// docstring if available - lookup the appropriate info
const auto& type_name = func.guessed_name.type_name;
const auto& state_name = func.guessed_name.state_name;
const auto& handler_kind = func.guessed_name.handler_kind;
const auto handler_name = handler_kind_to_name(handler_kind);
if (func.guessed_name.kind == FunctionName::FunctionKind::V_STATE) {
if (dts.virtual_state_metadata.count(type_name) != 0 &&
dts.virtual_state_metadata.at(type_name).count(state_name) != 0 &&
dts.virtual_state_metadata.at(type_name).at(state_name).count(handler_name) != 0) {
inline_body.insert(inline_body.begin(),
pretty_print::new_string(dts.virtual_state_metadata.at(type_name)
.at(state_name)
.at(handler_name)
.docstring.value()));
}
} else if (func.guessed_name.kind == FunctionName::FunctionKind::NV_STATE) {
if (dts.state_metadata.count(state_name) != 0 &&
dts.state_metadata.at(state_name).count(handler_name) != 0) {
inline_body.insert(inline_body.begin(),
pretty_print::new_string(
dts.state_metadata.at(state_name).at(handler_name).docstring.value()));
}
}
func.ir2.top_form->inline_forms(inline_body, func.ir2.env);
auto var_dec = func.ir2.env.local_var_type_list(func.ir2.top_form, func.type.arg_count() - 1);