Skip to content

Tool for analyzing code #4140

@markfirmware

Description

@markfirmware

I'd like a tool to help me as a code author to produce textual and visual commentary on the architecture and design principles and decisions used to write my code. Can I start with zig fmt to do that, or should I try something like f# or smalltalk?

For example, I am using stateful singletons to great effect in https://github.com/markfirmware/zig-bare-metal-microbit - I'd like something like a script that will find these in the code and list them or diagram them for the audience.

Working from https://github.com/markfirmware/zig-bare-metal-microbit/blob/master/mission03_model_railroad_button_controlled_pwm.zig

I can run this egrep and see that all the structs (except Button) are stateful singletons in that they have at least one var and no fields. Button has no var and at least one field so it is a record, maybe an object if it has functions (roughly speaking).

egrep '(struct|var .*= undefined;|:.*,$)' mission03_model_railroad_button_controlled_pwm.zig

const CycleActivity = struct {
    var cycle_counter: u32 = undefined;
    var cycle_time: u32 = undefined;
    var cycles_per_second: u32 = undefined;
    var last_cycle_counter: u32 = undefined;
    var last_cycle_start: ?u32 = undefined;
    var max_cycle_time: u32 = undefined;
    var up_time_seconds: u32 = undefined;
    var up_timer: TimeKeeper = undefined;
const ThrottleActivity = struct {
    var buttons: [2]Button = undefined;
    var pwm_loop_back_counter: u32 = undefined;
    const Button = struct {
        down_count: u32,
        index: u32,
        is_pressed: bool,
        is_simulation_pressed: bool,
        mask: u32,
        up_count: u32,
    const LedScroller = struct {
        var column: u32 = undefined;
        var displayed_percent: u32 = undefined;
        var text: []u8 = undefined;
        var text_buf: [text_len_max]u8 = undefined;
        var timer: TimeKeeper = undefined;
    const Throttle = struct {
        var pwm_width_ticks: u32 = undefined;
        var percent: u32 = undefined;
const TerminalActivity = struct {
    var keyboard_column: u32 = undefined;
    var prev_led_image: u32 = undefined;
    var prev_now: u32 = undefined;

I am particularly interested in something that helps me author commentary, although such a tool could be useful for studying someone else's product.

Metadata

Metadata

Assignees

No one assigned

    Labels

    use caseDescribes a real use case that is difficult or impossible, but does not propose a solution.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions