Skip to content

docs: template type alias docs generation and expression stringification - #262

Open
AkiSakurai wants to merge 1 commit into
WerWolv:masterfrom
AkiSakurai:gettype
Open

AkiSakurai wants to merge 1 commit into
WerWolv:masterfrom
AkiSakurai:gettype

Conversation

@AkiSakurai

Copy link
Copy Markdown
Contributor

The docs command has a regression where it outputs incomplete types. The generated documentation on https://docs.werwolv.net/pattern-language/libraries/type/base.pat renders the template type aliases as

using Dec<T> = ??? [[format(...)]];;

while the actual declaration is

using Dec<T> = T [[format("type::impl::format_dec")]];

Template parameter references print as '???' and attribute arguments are dropped entirely. This broke when type applications (ASTNodeTypeApplication) were introduced in #204: the docs generator was ported to the new node but never learned to print its template arguments. Before #204 the same declaration still rendered the complete

using Dec<T> = T [[format]];

with only the attribute arguments missing.

  • Split docs type helpers into docs_types.cpp (no CLI11 dependency for tests)
  • Implement expression and type name stringification as ASTStringifier, a visitor built on the AST visitor framework instead of dynamic_cast dispatch
  • Add stringifyTypeName/stringifyExpression with parent template param resolution
  • Precedence-aware parenthesization for math/ternary/cast expressions
  • Angle-bracket ambiguity parens for < > <= >= >> in template args
  • Preserve endianness (be/le) inside and outside template arguments
  • Keep unsigned literal suffixes (0u) in docs output so it round-trips back to the same literal; pattern type names keep their previous display format
  • Only fold "0 expr" back into unary "x" for the parser's signed-zero encoding, so a user-written "0u - x" keeps its value
  • Print attribute arguments via stringifyExpression (e.g. [[pack(1)]])
  • Skip invalid type decls in docs generation
  • Expand UsingDocs test coverage

The docs command has a regression where it outputs incomplete types. The
generated documentation on https://docs.werwolv.net/pattern-language/libraries/type/base.pat
renders the template type aliases as

    using Dec<T> = ??? [[format(...)]];;

while the actual declaration is

    using Dec<T> = T [[format("type::impl::format_dec")]];

Template parameter references print as '???' and attribute arguments are
dropped entirely. This broke when type applications (ASTNodeTypeApplication)
were introduced in WerWolv#204: the docs generator was ported to the new node but
never learned to print its template arguments. Before WerWolv#204 the same
declaration still rendered the complete

    using Dec<T> = T [[format]];

with only the attribute arguments missing.

- Split docs type helpers into docs_types.cpp (no CLI11 dependency for tests)
- Implement expression and type name stringification as ASTStringifier, a
  visitor built on the AST visitor framework instead of dynamic_cast dispatch
- Add stringifyTypeName/stringifyExpression with parent template param resolution
- Precedence-aware parenthesization for math/ternary/cast expressions
- Angle-bracket ambiguity parens for < > <= >= >> in template args
- Preserve endianness (be/le) inside and outside template arguments
- Keep unsigned literal suffixes (0u) in docs output so it round-trips back to
  the same literal; pattern type names keep their previous display format
- Only fold "0 <op> expr" back into unary "<op>x" for the parser's signed-zero
  encoding, so a user-written "0u - x" keeps its value
- Print attribute arguments via stringifyExpression (e.g. [[pack(1)]])
- Skip invalid type decls in docs generation
- Expand UsingDocs test coverage

Co-Authored-By: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant