werat wrote:

I went through the thread to understand the current consensus and I see various 
nice ideas flying around. Let me try to summarize the requirements and the 
current status quo.

* DIL should support synthetic children, whose names can be arbitrary in 
general case, even `a+b*c`
* A common synthetic name is `[0]`, which is used for children of vectors/maps 
and people want to write `print vec[0]`
  *  `frame variable` supports this by having special support for `[]` 
"expressions"
* We want DIL to be easy & convenient to use in most (simple) cases, but also 
to be able to support complicated cases and it doesn't have to be _super_ 
convenient for those

Possible behaviour for DIL:

* Make the definition of `identifier` in Lexer to roughly match C or similar
* Introduce escaping of identifiers, e.g. with backticks
  * The expression ``foo->`a*b.c`+1`` is parsed as approx 
`foo.GetChildWithName("a*b.c") + 1`
* Add special support for `[]` in the parser
  * The expression ``foo.`[1]` `` is parsed as `foo.GetChildWithName("[1]")`
  * The expression `foo[1]` tries the following:
    * `foo.GetChildWithName("1")`
    * `foo.GetChildWithName("[1]")`
    * `foo.GetChildAtIndex(1)`
  * The expression `foo["bar"]` tries:
    * `foo.GetChildWithName("bar")`
    * `foo.GetChildWithName("[bar]")`
  * The expression `foo[<expr>]` -- `expr` is evaluated and treated as cases 
above. If the result of `expr` is not a number or a string -- produce an error

For cases where the `GetChildWithName( "1" / "[1]" )` and `GetChildAtIndex(1)` 
produce different valid results we could shows a warning/error to make it clear 
to the user that there's some ambiguity. IMO this would be an improvement over 
the current situation where `print` and `expr` simply produce different results.


This way all typical cases work as expected by users and more or less match the 
current behaviour of frame variable. It's still possible to access synthetic 
children with any names, but it requires knowledge about the escaping.


Does this sound like a reasonable approach?

https://github.com/llvm/llvm-project/pull/123521
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to