// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)

////////////////////////////////
//~ rjf: Built-In Command Tables

@table(name                      ui_vis   ipc_docs_vis   q_slot       q_view  q_ent_kind  q_allow_files q_allow_folders  q_keep_oi   q_select_oi  q_is_code  q_required                     canonical_icon        string                        display_name                                  desc                                                                                                               search_tags                      )
//    /                          |        |              |             \___                                                       ____________________________________/                     |                     |                             |                                             |                                                                                                                  |
//   /                           |        |              |                 \                                                     /                                                          |                     |                             |                                             |                                                                                                                  |
D_CmdTable:     //               |        |              |                  |                                                   |                                                           |                     |                             |                                             |                                                                                                                  |
{
  //- rjf: low-level target control operations
  {LaunchAndRun                   1        1              EntityList         null              Target             0  0  0  0  0  1                                                           Play                  "launch_and_run"              "Launch and Run"                              "Starts debugging a new instance of a target, then runs."                                                          "launch,start,run,target"        }
  {LaunchAndInit                  1        1              EntityList         null              Target             0  0  0  0  0  1                                                           PlayStepForward       "launch_and_init"             "Launch and Initialize"                       "Starts debugging a new instance of a target, then stops at the program's entry point."                            "launch,start,entry,point"       }
  {Kill                           1        1              EntityList         null              Process            0  0  0  0  0  1                                                           Stop                  "kill"                        "Kill"                                        "Kills the specified existing debugged process(es)."                                                               "stop,kill"                      }
  {KillAll                        1        1              Null               null              Nil                0  0  0  0  0  0                                                           Stop                  "kill_all"                    "Kill All"                                    "Kills all debugged child processes."                                                                              "stop,kill,all"                  }
  {Detach                         1        1              EntityList         null              Process            0  0  0  0  0  1                                                           Null                  "detach"                      "Detach"                                      "Detaches the specified debugged process."                                                                         "detach"                         }
  {Continue                       1        1              Null               null              Nil                0  0  0  0  0  0                                                           Play                  "continue"                    "Continue"                                    "Continues all halted threads."                                                                                    ""                               }
  {StepIntoInst                   1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepInto              "step_into_inst"              "Step Into (Assembly)"                        "Performs a step that goes into calls, at the instruction level."                                                  "single,step,thread"             }
  {StepOverInst                   1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepOver              "step_over_inst"              "Step Over (Assembly)"                        "Performs a step that skips calls, at the instruction level."                                                      "single,step,thread"             }
  {StepIntoLine                   1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepInto              "step_into_line"              "Step Into (Line)"                            "Performs a step that goes into calls, at the source code line level."                                             "step,thread"                    }
  {StepOverLine                   1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepOver              "step_over_line"              "Step Over (Line)"                            "Performs a step that skips calls, at the source code line level."                                                 "step,thread"                    }
  {StepOut                        1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepOut               "step_out"                    "Step Out"                                    "Runs to the end of the current function and exits it."                                                            ""                               }
  {Halt                           1        1              Null               null              Nil                0  0  0  0  0  0                                                           Pause                 "halt"                        "Halt"                                        "Halts all running processes."                                                                                     "pause"                          }
  {SoftHaltRefresh                1        1              Null               null              Nil                0  0  0  0  0  0                                                           Refresh               "soft_halt_refresh"           "Soft Halt Refresh"                           "Interrupts all running processes to collect data, and then resumes them."                                         ""                               }
  {SetThreadIP                    0        1              Vaddr              null              Nil                0  0  0  0  1  1                                                           Null                  "set_thread_ip"               "Set Thread IP"                               "Sets the passed thread's instruction pointer at the passed address."                                              ""                               }
  
  //- rjf: high-level composite target control operations
  {RunToLine                      0        1              Null               null              Nil                0  0  0  0  0  0                                                           Play                  "run_to_line"                 "Run To Line"                                 "Runs until a particular source line is hit."                                                                      ""                               }
  {RunToAddress                   1        1              Vaddr              null              Nil                0  0  0  0  1  1                                                           PlayStepForward       "run_to_address"              "Run To Address"                              "Runs until a particular address is hit."                                                                          ""                               }
  {Run                            1        1              Null               null              Nil                0  0  0  0  0  0                                                           Play                  "run"                         "Run"                                         "Runs all targets after starting them if they have not been started yet."                                          "play"                           }
  {Restart                        1        1              Null               null              Nil                0  0  0  0  0  0                                                           Redo                  "restart"                     "Restart"                                     "Kills all running processes, then restarts the targets which were used to launch all current processes (if any)." "restart,retry"                  }
  {StepInto                       1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepInto              "step_into"                   "Step Into"                                   "Steps once, possibly into function calls, for either line or instructions."                                       ""                               }
  {StepOver                       1        1              Null               null              Nil                0  0  0  0  0  0                                                           StepOver              "step_over"                   "Step Over"                                   "Steps once, always over function calls, for either line or instructions."                                         ""                               }
  
  //- rjf: debug control context management operations
  {FreezeThread                   1        1              Entity             null              Thread             0  0  0  0  0  1                                                           Locked                "freeze_thread"               "Freeze Thread"                               "Freezes the passed thread."                                                                                       "callstack,unwind"               }
  {ThawThread                     1        1              Entity             null              Thread             0  0  0  0  0  1                                                           Unlocked              "thaw_thread"                 "Thaw Thread"                                 "Thaws the passed thread."                                                                                         ""                               }
  {FreezeProcess                  1        1              Entity             null              Process            0  0  0  0  0  1                                                           Locked                "freeze_process"              "Freeze Process"                              "Freezes the passed process."                                                                                      ""                               }
  {ThawProcess                    1        1              Entity             null              Process            0  0  0  0  0  1                                                           Unlocked              "thaw_process"                "Thaw Process"                                "Thaws the passed process."                                                                                        ""                               }
  {FreezeMachine                  0        1              Entity             null              Machine            0  0  0  0  0  1                                                           Locked                "freeze_machine"              "Freeze Machine"                              "Freezes the passed machine."                                                                                      ""                               }
  {ThawMachine                    0        1              Entity             null              Machine            0  0  0  0  0  1                                                           Unlocked              "thaw_machine"                "Thaw Machine"                                "Thaws the passed machine."                                                                                        ""                               }
  {FreezeLocalMachine             1        1              Null               null              Nil                0  0  0  0  0  0                                                           Machine               "freeze_local_machine"        "Freeze Local Machine"                        "Freezes the local machine."                                                                                       ""                               }
  {ThawLocalMachine               1        1              Null               null              Nil                0  0  0  0  0  0                                                           Machine               "thaw_local_machine"          "Thaw Local Machine"                          "Thaws the local machine."                                                                                         ""                               }
  {FreezeEntity                   0        0              Null               null              Nil                0  0  0  0  0  0                                                           Null                  "freeze_entity"               "Freeze Entity"                               "Freezes an entity."                                                                                               ""                               }
  {ThawEntity                     0        0              Null               null              Nil                0  0  0  0  0  0                                                           Null                  "thaw_entity"                 "Thaw Entity"                                 "Thaws an entity."                                                                                                 ""                               }
  
  //- rjf: entity decoration
  {SetEntityColor                 0        0              Null               null              Nil                0  0  0  0  0  0                                                           Null                  "set_entity_color"            "Set Entity Color"                            "Sets the passed entity's color."                                                                                  ""                               }
  {SetEntityName                  0        0              Null               null              Nil                0  0  0  0  0  0                                                           Null                  "set_entity_name"             "Set Entity Name"                             "Sets the passed entity's name."                                                                                   ""                               }
  
  //- rjf: attaching
  {Attach                         1        1              PID                null              Nil                0  0  0  0  0  1                                                           Null                  "attach"                      "Attach"                                      "Attaches to a process that is already running on the local machine."                                              ""                               }
}

@enum D_CmdKind:
{
  Null,
  @expand(D_CmdTable, a) `$(a.name)`,
  COUNT,
}

////////////////////////////////
//~ rjf: Built-In View Rules

@table(coverage_check  name  name_lower  string          ih  ex  xp  vb                display_name                  docs    schema                                                         description)
D_ViewRuleTable:
{
  {x  Default    default     "default"                    -   -   -   x                 "Default"                     -       ""                                                             ""                                                                                                                                                                           }
  {x  Array      array       "array"                      -   -   x   -                 "Array"                       x       "x:{expr}"                                                     "Specifies that a pointer points to N elements, rather than only 1."                                                                                                         }
  {x  Slice      slice       "slice"                      -   -   x   -                 "Slice"                       x       ""                                                             "Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer."                                             }
  {-  List       list        "list"                       -   -   -   x                 "List"                        x       "x:{member}"                                                   "Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."                              }
  {x  ByteSwap   bswap       "bswap"                      x   -   x   -                 "Byte Swap"                   x       ""                                                             "Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed."                                                                    }
  {x  Cast       cast        "cast"                       -   -   x   -                 "Cast"                        x       "x:{type}"                                                     "Specifies that the expression to which the view rule is applied should be casted to the provided type."                                                                     }
  {-  BaseDec    base_dec    "dec"                        x   -   -   -                 "Decimal Base (Base 10)"      x       ""                                                             "Specifies that all integral evaluations should appear in base-10 form."                                                                                                     }
  {-  BaseBin    base_bin    "bin"                        x   -   -   -                 "Binary Base (Base 2)"        x       ""                                                             "Specifies that all integral evaluations should appear in base-2 form."                                                                                                      }
  {-  BaseOct    base_oct    "oct"                        x   -   -   -                 "Octal Base (Base 8)"         x       ""                                                             "Specifies that all integral evaluations should appear in base-8 form."                                                                                                      }
  {-  BaseHex    base_hex    "hex"                        x   -   -   -                 "Hexadecimal Base (Base 16)"  x       ""                                                             "Specifies that all integral evaluations should appear in base-16 form."                                                                                                     }
  {-  Only       only        "only"                       x   -   -   x                 "Only Specified Members"      x       "x:{member}"                                                   "Specifies that only the specified members should appear in struct, union, or class evaluations."                                                                            }
  {-  Omit       omit        "omit"                       x   -   -   x                 "Omit Specified Members"      x       "x:{member}"                                                   "Omits a list of member names from appearing in struct, union, or class evaluations."                                                                                        }
  {-  NoAddr     no_addr     "no_addr"                    x   -   -   -                 "Disable Address Values"      x       ""                                                             "Displays only what pointers point to, if possible, without the pointer's address value."                                                                                    }
  {x  Checkbox   checkbox    "checkbox"                   -   -   -   -                 "Checkbox"                    x       ""                                                             "Displays simple integer values as checkboxes, encoding zero or nonzero values."                                                                                             }
  {-  ColorRGBA  color_rgba  "color_rgba"                 -   x   -   x                 "Color (RGBA)"                x       ""                                                             "Displays as a color, interpreting the data as encoding R, G, B, and A values."                                                                                              }
  {x  Text       text        "text"                       -   x   -   x                 "Text"                        x       "x:{'lang':lang, 'size':expr}"                                 "Displays as text."                                                                                                                                                          }
  {x  Disasm     disasm      "disasm"                     -   x   -   x                 "Disassembly"                 x       "x:{'arch':arch, 'size':expr}"                                 "Displays as disassembled instructions, interpreting the data as raw machine code."                                                                                          }
  {x  Memory     memory      "memory"                     -   x   -   x                 "Memory"                      x       "x:{'size':expr}"                                              "Displays as a raw memory grid."                                                                                                                                             }
  {-  Graph      graph       "graph"                      -   x   -   x                 "Graph"                       x       ""                                                             "Displays as a pointer graph, visualizing nodes and edges formed by pointers directly."                                                                                      }
  {x  Bitmap     bitmap      "bitmap"                     -   x   -   x                 "Bitmap"                      x       "x:{'w':expr, 'h':expr, 'fmt':tex2dformat}"                    "Displays as a bitmap, interpreting the data as raw pixel data."                                                                                                             }
  {-  Geo3D      geo3d       "geo3d"                      -   x   -   x                 "Geometry (3D)"               x       "x:{'count':expr, 'vtx':expr, 'vtx_size':expr}" "Displays as geometry, interpreting the data as index or vertex data."                                                                                                                      }
}

@enum D_ViewRuleKind:
{
  @expand(D_ViewRuleTable a) `$(a.name)`,
  COUNT,
}

@data(D_ViewRuleSpecInfo) @c_file d_core_view_rule_spec_info_table:
{
  @expand(D_ViewRuleTable a)
    ```{str8_lit_comp("$(a.string)"), str8_lit_comp("$(a.display_name)"), str8_lit_comp("$(a.schema)"), str8_lit_comp("$(a.description)"), (D_ViewRuleSpecInfoFlag_Inherited*$(a.ih == "x"))|(D_ViewRuleSpecInfoFlag_Expandable*$(a.ex == "x"))|(D_ViewRuleSpecInfoFlag_ExprResolution*$(a.xp == "x"))|(D_ViewRuleSpecInfoFlag_VizBlockProd*$(a.vb == "x")), }```;
}

////////////////////////////////
//~ rjf: Developer Toggles

@table(name)
D_DevToggleTable:
{
  {telemetry_capture}
  {simulate_lag}
  {draw_ui_text_pos}
  {draw_ui_focus_debug}
  {draw_ui_box_heatmap}
  {eval_compiler_tooltips}
  {eval_watch_key_tooltips}
  {cmd_context_tooltips}
  {scratch_mouse_draw}
  {updating_indicator}
}

@gen
{
  @expand(D_DevToggleTable a) `global B32 DEV_$(a.name) = 0;`
}

@gen
{
  `struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] =`;
  `{`;
    @expand(D_DevToggleTable a) `{&DEV_$(a.name), str8_lit_comp("$(a.name)")},`
      `};`;
}
