[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue 5309, take 2: find_global_context () and find_score_context ()
nine . fierce . ballads
Re: Issue 5309, take 2: find_global_context () and find_score_context () (issue 561290043 by address@hidden)
Fri, 03 Jan 2020 08:34:13 -0800
On 2020/01/03 16:18:10, lemzwerg wrote:
lily/context.cc:116: if (Context *score = gthis->get_score_context ())
Not sure whether compilers warn about the `if (... = ...)` construct.
the `Context *` prevents it. Otherwise I suggest another level of
I've compiled context.o with "-Wall -Wextra" with g++ 9.2.1, and there
is no complaint.
1: find_score_context ()
Translator::find_score_context () finds the Score context enclosing
the Translator in a way similar to (but slightly more direct than)
\set Score.whatever = ... rather than depending on the global context.
Global_context::get_score_context () returns the first child, as
before, but it is no longer a virtual method of Context, and it is used
in fewer places.
2: find_global_context ()
Replace c->get_global_context () with find_global_context (c). This
function does not need to access any private information of Context, so
pulling it out simplifies the interface of Context. Calling it "find"
rather than "get" is supposed to imply more work (walking the tree).
Implement find_global_context (c) as find_top_context (c) plus a type
check. This increases code reuse and requires fewer dynamic casts.
Abort the program if the top context is not a Global context, otherwise
most callers would dereference null pointers.
* * *
These changes update and expand on changes previously reviewed in
Please review this at https://codereview.appspot.com/561290043/
Affected files (+70, -81 lines):