Question about injectContext
David Nolden
david.nolden.kdevelop at art-master.de
Tue Mar 22 19:18:03 UTC 2011
2011/3/22 Sven Brauch <svenbrauch at googlemail.com>:
> I'd like to create a member variable declaration for a class if an
> attribute is written at any instance of that class, for example (A is
> a class): "instance = A(); instance->x = 3" -- then I'd like to create
> a class member declaration for x, if none exists yet.
> Isn't this the use case injectContext is meant for? I would like to
No, at least in C++, injectContext is mainly just used for to
temporarily change the visibility to have the same visibility as from
within the given context (at least from what I remember).
The deletion of the declarations most probably happens because the
declaration cannot be matched properly during updating. Whenever the
context is re-parsed, the declaration-builder notices that the
declaration was not matched, and deletes it again. This happens
because you don't create the declaration while the context is _really_
built. The issue regarding the navigation-widget happens because the
duchain does the sane assumption that each declaration happens within
the range of the enclosing context.
I have already thought about these issues for languages like python,
and I think the solution would be:
1) Add a "isAutoDeclaration" 1-bit bool flag to Declaration, which
says whether the declaration was created "automatically" through a use
of it, and always declare this for python variables.
2) In the context-builder while closing a context: Instead of deleting
all non-encountered declarations, leave alive non-encountered
declarations with the "isAutoDeclaration" flag _only if_ it has uses.
3) When the declaration is used:
4.1) If the declaration does not exist yet, create it the way you're
doing now, but with an empty range that is contained by the correct
class-context, and with the isAutoDeclaration set.
4.2) Create a use of the declaration, with the correct range. This
will make the navigation-widget work.
I think this would be the most clean way to do it. Maybe the php
developers also have something to add, as they might be dealing with
similar issues.
Greetings, David
More information about the KDevelop-devel
mailing list