Skip to content

Document enum values #1209

@Euphoria-MJansen

Description

@Euphoria-MJansen

Summary

Enum constants in the mrdocs DOM only expose initializer as written in the source. For enum constants with no explicit initializer, nothing is available at all.

Motivation

Consider:

#define BASE_VALUE 0x02000000

enum MyEnum {
    FirstValue = BASE_VALUE,  // initializer = "BASE_VALUE" (macro name, not resolved)
    SecondValue,              // no initializer at all
    ThirdValue,               // no initializer at all
};

The documentation generated for this enum shows (with a template modification):

Name Value
FirstValue BASE_VALUE
SecondValue (empty)
ThirdValue (empty)

What I would need:

Name Value
FirstValue 33554432
SecondValue 33554433
ThirdValue 33554434

For protocol or wire-format enums where the numeric value is the essential piece of information, the unresolved macro name and missing implicit values are not useful.

Proposed change

Add a value field to enum-constant DOM objects containing the evaluated integer as a decimal string. The existing initializer field (source text) should remain for cases where showing the expression is preferred.

Example DOM (XML):

<enum-constant>
  <name>FirstValue</name>
  <initializer>BASE_VALUE</initializer>
  <value>33554432</value>
</enum-constant>
<enum-constant>
  <name>SecondValue</name>
  <value>33554433</value>
</enum-constant>

The Handlebars template could then use {{value}} (or fall back to {{initializer}}) to show the number.


Note: most of this ticket is generated using AI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions