class FormatNode

Defined at line 48 of file ../../src/developer/debug/zxdb/expr/format_node.h

A node in a tree of formatted "stuff" for displaying the user. Currently this stuff can be

expressions which are evaluated, and ExprValue classes which contain already-evaluated values.

This tree can represent expansions for things like struct members.

DESIGN

------

Think of this class as being a tree node in a GUI debugger's "watch" window. The "source" is the

most fundamental thing that the node represents. They can be expressions which are evaluated in

the current context or can be derived automatically from a parent value (say class members).

The node can be in several states. It can be empty (State::kEmpty), it can have an expression

that hasn't been evaluated (State::kUnevaluated, say for a tree node where the user has typed a

watch expression in), that expression can be evaluated to get an ExprValue (a value + type =

State::kHasValue), and that type to get a stringified description + type (State::kDescribed). A

node can also have an error state. A node might not go through all states, to format a known

value, the FormatNode can be given a value directly, skipping the "expression" state.

Frontend code can take this tree and format it however is most appropriate for the environment.

CHILDREN

--------

A node can have children. The most obvious example is structure members. Children can also be

anything else that might be expanded from a parent, including base classes or pointer

dereferences (again, imagine a watch window tree view).

"Describing" a node will fill in the children as well as the single-line description. The

children might not themselves be evaluated or described until explicitly filled. This allows lazy

expansion for things like pointer dereferencing where computing the fully described value might

be slow or infintely recursive.

Public Methods

void FormatNode (const std::string & name)

Constructor for an empty node. Empty nodes have optional names.

Defined at line 13 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (const std::string & name, ExprValue value)

Constructor for a known value.

Defined at line 15 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (const std::string & name, ErrOrValue err_or_value)

Defined at line 22 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (const std::string & name, Err err)

Constructor for the error case.

Defined at line 30 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (const std::string & name, const std::string & expression)

Constructor with an expression.

Defined at line 33 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (const std::string & name, GetProgramaticValue get_value)

Constructor for a programatically-filled value.

Defined at line 40 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FormatNode (GroupTag )

Defined at line 49 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void ~FormatNode ()

Not copyable nor moveable since this doesn't work with the weak ptr factory.

Defined at line 55 of file ../../src/developer/debug/zxdb/expr/format_node.cc

fxl::WeakPtr<FormatNode> GetWeakPtr ()

Defined at line 57 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void FillProgramaticValue (const fxl::RefPtr<EvalContext> & context, fit::deferred_callback cb)

Call when source == kProgramatic to fill the value from the getter. The callback will be issued

(possibly from within this call stack) when the value is filled.

Defined at line 59 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void SetValue (ExprValue v)

The value. This will be valid when the State == kHasValue. The description and type might not

be up-to-date, see FillFormatNodeDescription().

The setter is out-of-line because we expect this will need to send change notifications in the

future.

Defined at line 75 of file ../../src/developer/debug/zxdb/expr/format_node.cc

void SetDescribedError (const Err & e)

Defined at line 80 of file ../../src/developer/debug/zxdb/expr/format_node.cc

Source source ()

Defined at line 150 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_source (Source s)

Defined at line 151 of file ../../src/developer/debug/zxdb/expr/format_node.h

State state ()

Defined at line 153 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_state (State s)

Defined at line 154 of file ../../src/developer/debug/zxdb/expr/format_node.h

ChildKind child_kind ()

See the ChildKind enum above. This is set by the parent node when it creates a child.

Defined at line 157 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_child_kind (ChildKind ck)

Defined at line 158 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_name (const std::string & n)

The name of this node. This is used for things like structure member names when nodes are

expanded. For nodes with an expression type, this name is not used.

Defined at line 162 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & name ()

Defined at line 163 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & expression ()

When source() == kExpression this is the expression to evaluate. Use FillFormatNodeValue() to

convert this expression to a value.

Defined at line 167 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_expression (std::string e)

Defined at line 168 of file ../../src/developer/debug/zxdb/expr/format_node.h

const ExprValue & value ()

Defined at line 180 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & type ()

The type() is the stringified version of value_.type(). It is valid when State == kDescribed.

Defined at line 183 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_type (std::string t)

Defined at line 184 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & description ()

The short description of this node's value. It is valid when State == kDescribed. For composite

things like structs, the description might be an abbreviated version of the struct's members.

Defined at line 188 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_description (std::string d)

Defined at line 189 of file ../../src/developer/debug/zxdb/expr/format_node.h

DescriptionKind description_kind ()

Defined at line 191 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_description_kind (DescriptionKind dk)

Defined at line 192 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & wrapper_prefix ()

When this is a "wrapper" node the formatter node will want to provide a begin and end string

for expressing the contained object. For example prefix = "std::optional(", suffix = ")".

NOTE FOR FUTURE: We may want to expand this to be usable for non-wrappers also. Currently the

console frontend knows that Rust structs get a certain type prefix and that tuples get certain

types of backets, but that information could be expressed here instead since it may be

desirable for all situations, not just the console frontend. For that, we may also want to add

a "verbose" prefix and a "regular" prefix.

Defined at line 202 of file ../../src/developer/debug/zxdb/expr/format_node.h

const std::string & wrapper_suffix ()

Defined at line 203 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_wrapper_prefix (const std::string & s)

Defined at line 204 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_wrapper_suffix (const std::string & s)

Defined at line 205 of file ../../src/developer/debug/zxdb/expr/format_node.h

const ChildVector & children ()

Defined at line 207 of file ../../src/developer/debug/zxdb/expr/format_node.h

ChildVector & children ()

Defined at line 208 of file ../../src/developer/debug/zxdb/expr/format_node.h

const Err & err ()

There could have been an error filling in the node. The error could be from computing the value

of the expression, or in formatting the ExprValue.

The state of the node will represent the last good state. So if there was an error evaluating

the expression, the state will be "unevaluated" and it could be evaluated again in a new

context to resolve the error. If there was an error formatting the value (say symbols are

incorrect) the state will be "has value" and in this case trying to reevaluate won't recover

from the error without the value changing.

Defined at line 218 of file ../../src/developer/debug/zxdb/expr/format_node.h

void set_err (const Err & e)

Defined at line 219 of file ../../src/developer/debug/zxdb/expr/format_node.h

Enumerations

enum Source
Name Value
kValue 0
kExpression 1
kProgramatic 2
kDescription 3

The original source or the value for this node.

Defined at line 64 of file ../../src/developer/debug/zxdb/expr/format_node.h

enum DescriptionKind
Name Value
kNone 0
kGroup 1
kArray 2
kBaseType 3
kCollection 4
kFunctionPointer 5
kOther 6
kPointer 7
kReference 8
kRustEnum 9
kRustTuple 10
kRustTupleStruct 11
kString 12
kWrapper 13

The kind of thing the description describes. This is set when the node is put in the described

state according to what it evaluated to.

Defined at line 73 of file ../../src/developer/debug/zxdb/expr/format_node.h

enum ChildKind
Name Value
kNormalChild 0
kBaseClass 1
kArrayItem 2
kPointerExpansion 3
kVariable 4

What this node means to its parent. This is not based on the value in any way and can only

be computed by the parent.

Defined at line 92 of file ../../src/developer/debug/zxdb/expr/format_node.h

enum State
Name Value
kEmpty 0
kUnevaluated 1
kHasValue 2
kDescribed 3

See the class comment above about the lifecycle.

Defined at line 116 of file ../../src/developer/debug/zxdb/expr/format_node.h

Records